fix(Android): don't remount components during navigation on the new architecture#11806
fix(Android): don't remount components during navigation on the new architecture#11806satya164 merged 3 commits intoreact-navigation:mainfrom
Conversation
✅ Deploy Preview for react-navigation-example ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Thanks for the PR. Isn't this a bug in React Native if the view nesting level changes like this? Or is this specific interaction with view flattening and react-native-screens? Also can you add a comment before the line in the code with the details? |
|
It's caused by this line: I guess when overflow gets changed to hidden the criteria for collapsing the view are met, so it's removed.
It's reproducible without
I've added a high-level explanation, is it good enough or should I go more in-depth? |
|
I have updated the comment. Will merge the workaround for now, tho I think it'd be good to open this issue in React Native repo as imo view flattening should be only an optimization and not observable like this, and this doesn't happen in the old architecture. |
Motivation
This PR prevents the native view hierarchy built by
Stackfrom re-mounting to prevent blurring focus - when a view is removed from the hierarchy it's blurred on Android, but it's not focused back when added again. Due to one of the views in theCardcomponent being flattened, children ofCardwere removed from the hierarchy and attached under a different parent.Before the change
Screen.Recording.2024-02-01.at.11.45.27.mov
Native hierarchy on the first screen:

Native hierarchy on the second screen:

Notice the different nesting levels between the two - one of the views got collapsed during navigation.
After the change
Screen.Recording.2024-02-01.at.11.45.45.mov
Native hierarchy on the first screen:

Native hierarchy on the second screen:

Notice the same nesting levels between the two.
Test plan
I've tested the change on the following code