-
Notifications
You must be signed in to change notification settings - Fork 109
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
[ANDROID] Sign Out -> Back Press -> Going back to Profile page #1
Comments
Ahh thank you for catching this! It makes sense that this would be happening. One of the downsides of not being a full-time Android user - forget about those things 😄 I'll have to think about a solution to this one 🤔 (happy to receive any input from you or others!) |
I have a partial solution to the matter. I've used the Reset option from Navigation Actions to clear the accumulated stack. However, the only limitation I found for this approach is that if there is a nested stack involved, then it is not able to route to the child screens in one inner stack to another inner stack. I could only get it to work in my application by having only one stack. |
In Profile.js replace Button component with |
Toyed around with this a bit today but without much success. Was blocked at the same point as you @saidhruv. I wonder if there's a way to set up a custom If we could figure that out we could probably simplify/modify this whole thing and remove the |
Though a workaround, this seems to be working for nested stacks.
Got it from here. |
I guess it would be possible to use redux and redux-persist to handle your loggedIn state, which in turn gets used by createRootNavigator. So upon login you change your state and the router will rerender. Haven't tried it though, but sounds plausible. However, it would make life so much easier if you could just pass a type for the navigation, like in the react-native-router-flux syntax (type: 'reset'). |
I think I might have a possible solution: Here is my use case - I have the following routes:
The user must not go back to any of the previous routes once they come to the next routing flow, i.e, from EnterPhoneNumber screen, they shouldn't be able to go back to the Splash screen and so on. My previous attempts ended up giving some errors, but routing like the following way does not give any error as far as I've seen: this.props.navigation.dispatch(
NavigationActions.reset({
index: 0,
key: null,
actions: [
NavigationActions.navigate({
routeName: 'VerifyPhoneNumberFlow',
action: [NavigationActions.navigate({ routeName: 'EnterPhoneNumber' })],
}),
],
}), @spencercarli could you look into it and let me know if this solves the problem? |
@saidhruv I have pretty much the same nav stack as you do, but unfortunately I get the same error using your fix. Which version of react-navigation are you using? Im using "1.0.0-beta.10" |
+1 |
@WillyRamirez I use 1.0.0-beta.11 |
I did it by using dispatch to reset the signedout or singedin navigation with 0 index here is my code. export const ResetToSignedOut=NavigationActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: 'SignedOut' })],
})
export const ResetToSignedIn = NavigationActions.reset({
index: 0,
key: null,
actions: [
NavigationActions.navigate({ routeName: 'SignedIn' })
]
}) and from SignIn.js file navigate to home as: onSignIn().then(() => navigation.dispatch(ResetToSignedIn)) and from the profile.js navigate to sign out as: onSignOut().then(() => navigation.dispatch(ResetToSignedOut)) |
@Shhzdmrz Will you please share your code This problem is solved or not because i am facing same issue, Even i tried with navigation reset but nothing worked out , After using navigation reset call facing this error There is no route defined for key SignedIn. |
@sunnynegi I have posted my answer to you SO thread. |
Thanks @spencercarli for the guide ! |
You can disable the back button using BackHandler provided by ReactNative.Let me know if you need any help |
I face the same issue as sunnynegi. I looked at the solution provided by Shhzdmrz on SO but so far, still get the same error |
This is an Android only issue, since iOS does not have a dedicated Back button.
Loaded the application on Android as recommended, navigated to the 'Profile' tab and clicked 'Sign Out' which led me back to the 'Sign Up' page. However, on pressing the back button, it is going to the 'Profile' tab.
Shouldn't the entire stack be cleared on Sign Out?
This is the same for the Sign In flow too.
Sign Up -> Sign In -> Click Sign In -> Home -> Back Press -> Sign In
The text was updated successfully, but these errors were encountered: