react-navigation.github.io icon indicating copy to clipboard operation
react-navigation.github.io copied to clipboard

Can't keep a screen mounted

Open florian-milky opened this issue 4 years ago • 6 comments

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.

florian-milky avatar Jun 11 '20 14:06 florian-milky

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.

Rangoons avatar Jun 11 '20 15:06 Rangoons

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

florian-milky avatar Jun 12 '20 10:06 florian-milky

I am also interested in an official workaround for this

timnlupo avatar Aug 17 '20 04:08 timnlupo

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

meshaabi avatar Aug 24 '20 21:08 meshaabi

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

kpetrow avatar Jun 09 '21 19:06 kpetrow

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

kpetrow avatar Jul 13 '21 19:07 kpetrow