-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
[v5] Navigation glitch after first entering stack #6651
Comments
Please provide repro code |
Hello Satyajit, I have created a minimal repository to reproduce the issue at hand. https://github.com/ewnavilae/rnnavbug There is a small patch (although it looks like it changes a lot of things because I saved the formatting) that allows custom onTabPress in order to open a menu when tab 4 is pressed. The setup I use with this repository is as follows:
Afterwards, the intended behaviour when using the application is:
The observed behaviour is:
It appears as though the history in the "More" stack is being preserved despite going back in step 3. I still believe I could be doing something wrong, so thank you for your response and taking the time to analyze this issue. |
Can you update to the latest alpha please? You're on an old version. |
Satyajit, I had tried updating the packages for the last month since I posted the issue and I have updated the repository to the latest version and the problem still persists. I used the following command to update: Current versions:
Can you confirm the issue occurs as described? Thank you |
I ran the example you provided both on iOS and Android, but pressing tab 4 doesn't open any menu.
Going to a different tab doesn't unmount previous tabs. This is the expected behaviour and it was the same in React Navigation 4. I presume the "glitch" you're describing is just the screen transition animation of the stack. From the behaviour you are describing that you want, sounds like you don't want it to behave like a stack (no stack history, no animation etc.). Since you don't want the behaviour of stack, I'd suggest that instead of rendering a stack, render a normal component, pass what you want to render as params and return the component appropriately: function MoreScreen(route) {
switch(route.params?.screen) {
case 'Settings':
return <Settings />;
case 'Dashboard'
return <Dashboard />;
}
}
// ...
navigation.navigate('More', { screen: 'Settings' }); |
Screens are removed from history, but they aren't unmounted in tab navigator or drawer navigator. Tab navigator doesn't behave the same as stack.
You'll need to adapt it to fit your app. You can't use Stack because the the behavior you want isn't how Stack Navigator behaves. The behavior you want is more like how tab navigator behaves with
I missed patch package (you should add it to postinstall instead of another command). But anyway, the behavior is the expected behavior and is the same as previous versions of React Navigation. This is not a bug. |
That's right, sorry, I was in a rush to get the repro ready as this is a long standing issue that could block the release of the application I'm working on! So if I got it correctly, the first screen I ever access in that stack is there simply because when I go back to another tab, the stack is not unmounted? I have managed to work around this problem by applying the following code in the MoreStack navigator:
And by returning null when mounted is false. I think maybe a switch navigator would be more appropriate for my use case, is it being removed in the 5.0 version? Thank you very much for helping me clear up this issue. |
Sorry for not using the template but it wouldn't make sense to do so in this case as the problem is pretty clear and easy to reproduce. I also apologize if I lack politeness or coherence as I have been trying to workaround this bug for an enormous amount of time and it has frustrated me deeply.
I am using "next" version for everything.
TL;DR first: After navigating to any screen inside a stack, subsequent navigations to screens inside that stack first push the initial screen and only then the newly navigated-to screen.
I have a simple navigation setup where I use a <Stack.Navigator> that handles authentication flow, then an Application stack using MaterialBottomTabsNavigator inside of which I have all of my application's screens.
One of these screens is a Stack.Navigator called More and here is where the issue is happening:
Whenever I navigate inside a screen of this Stack, using
navigation.navigate( "More", { screen: "ExampleScreen" } )
, there is no problem the first time, but every other navigate call I make to a screen inside More first renders the first More screen loaded, then the screen I actually navigated to, making it so if I go back it returns to that screen first instead of the screen I was in.Example of the described behaviour:
I am only using @react-navigation/stack stacks and a single @react-navigation/material-bottom-tabs stack, therefore my structure is:
I have tried everything to work around this bug such as navigation differently (with dispatch, with resetRoot), attempting to clear the history for the More stack, etc. and everything simply resulted in more unexpected behaviour.
You can see a gif of the situation described:
![ezgif-4-67efd73809e8](https://user-images.githubusercontent.com/7836920/70248849-759b2080-1773-11ea-975f-18e1e614174a.gif)
Does this problem make sense to anyone? I wanted to see if maybe someone else has experienced this or anyone has an idea of what it could be before I go and spend additional time in creating a test repo.
The text was updated successfully, but these errors were encountered: