react-navigation.github.io
react-navigation.github.io copied to clipboard
Can't keep a screen mounted
Current Behavior
From the docs:
navigation.navigate({ name: SCREEN, key: SCREEN_KEY_A });
navigation.navigate({ name: SCREEN, key: SCREEN_KEY_B });
navigation.navigate({ name: SCREEN, key: SCREEN_KEY_C });
navigation.navigate({ name: SCREEN, key: SCREEN_KEY_D });
then
navigation.navigate({ key: SCREEN_KEY_A }); // will go to screen A FROM screen D
It will unmount B, C and D. (btw I think this should be highlighted more in the docs) What if I want to keep let's say D mounted? And when I navigate to D again, I want to reuse the same instance.
My use case is a webview that I want to keep mounted in the background. I found an old question in stackoverflow, never answered https://stackoverflow.com/questions/41818857/keep-react-native-webview-mounted
Expected Behavior
- I want to have the option to keep a screen mounted and reuse the same instance when I navigate back to it.
I've noticed this today too. I believe it was a change that was introduced recently. I would love to know a fix for it.
For reference, in a Stack, the first route/screen is a Tab nav that contains different feeds. Pressing an item in the feed navigates to a details page, which is another screen in the stack, navigation.goBack()
resets the tab position.
I found a workaround which is to put your screen in a tab navigator at the top level navigation and hide it. See https://github.com/react-navigation/react-navigation/issues/4069
I am also interested in an official workaround for this
hmm would it work as expected if you use .push instead of .navigate ?
taken me round 6 hours to find this thread... Is there any solution?
BUMP. I was able to use a couple workarounds but now need some more nesting that keeps resetting the state of my webview when i navigate back to it. Would be really nice to get a solution to this