react-navigation / react-navigation.github.io

Home of the documentation and other miscellanea
https://reactnavigation.org/
MIT License
312 stars 1.89k forks source link

Can't keep a screen mounted #808

Open florian-milky opened 4 years ago

florian-milky commented 4 years ago

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

Rangoons commented 4 years ago

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.

florian-milky commented 4 years ago

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

timnlupo commented 4 years ago

I am also interested in an official workaround for this

meshaabi commented 4 years ago

hmm would it work as expected if you use .push instead of .navigate ?

kpetrow commented 3 years ago

taken me round 6 hours to find this thread... Is there any solution?

kpetrow commented 3 years ago

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