Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inactive screen visible for one frame #11315

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

WoLewicki
Copy link
Member

@WoLewicki WoLewicki commented Apr 3, 2023

In a scenario when we have 3 screens pushed on the stack (let's name them A, B, C in the nesting order) and we navigate from C to B, the A screen was attached for about one frame (and it should not be since it will not be visible after transition), causing problems with libraries that subscribe to native attach/detach process.

It happened because when the third screen disappears, the length of the routes becomes smaller, so in our case length becomes 2, activeScreensLimit is still 1, so we do go into else in line 609 for screen A, which was inactive during the transition. In there, the outputValue is set correctly to STATE_INACTIVE for after the transition, but it is interpolated from 1 to 0(STATE_INACTIVE) (lines 611-616), so it gets the 1 value. The transition ends in the next frame, so it quickly becomes 0 again, but still was attached for this one frame.

The solution is to keep the information of what was the last state for each index, and if it was STATE_INACTIVE and will be such after the transition, there is no sense to make it visible. It would be nice to test it in many scenarios for sure.

@graszka22 can confirm that it fixes a problem with native attach/detach in their library.

@netlify
Copy link

netlify bot commented Apr 3, 2023

Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit d384587
🔍 Latest deploy log https://app.netlify.com/sites/react-navigation-example/deploys/65ee005a8169e700082ded2b
😎 Deploy Preview https://deploy-preview-11315--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

Hey @autofix-ci[bot]! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2023

Codecov Report

Attention: Patch coverage is 76.74419% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 77.16%. Comparing base (99d0385) to head (d384587).

Files Patch % Lines
packages/stack/src/views/Stack/CardStack.tsx 76.74% 10 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11315      +/-   ##
==========================================
+ Coverage   77.12%   77.16%   +0.04%     
==========================================
  Files         211      211              
  Lines        6269     6280      +11     
  Branches     2475     2481       +6     
==========================================
+ Hits         4835     4846      +11     
  Misses       1380     1380              
  Partials       54       54              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonathanm-tkf
Copy link

Hi @WoLewicki thanks for this fix, is it possible to apply this same fix to @react-navigation/native-stack? could you guide me on which files to modify because I have the same behavior but in this package?

Thank you very much

@WoLewicki
Copy link
Member Author

@jonathanm-tkf native-stack does not operate on those values and their attach/detach process is handled by the platform, so it shouldn't be a problem there. Do you see the same behavior there?

@jonathanm-tkf
Copy link

Correct @WoLewicki, the temporary fix I made was to place a normal stack and then a native-stack inside, I don't know if this is the best way to solve it.

@kacperkapusciak kacperkapusciak self-requested a review July 31, 2023 12:47
@@ -609,6 +622,7 @@ export class CardStack extends React.Component<Props, State> {
})
: STATE_TRANSITIONING_OR_BELOW_TOP;
}
this.lastActivityStateForIndex[index] = isScreenActive;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes render impure. We need to figure out an alternative way that keeps render pure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an idea what could we do to achieve it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's have a call to understand the logic and come up with an idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember much more than what is written in the description of the PR, but we can do that for sure 😅

@satya164 satya164 force-pushed the @wolewicki/fix-one-frame-active-screen branch from d9a76fb to 6f56ff2 Compare March 10, 2024 18:44
@satya164 satya164 force-pushed the @wolewicki/fix-one-frame-active-screen branch from 6f56ff2 to d384587 Compare March 10, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants