Skip to content

Instantly share code, notes, and snippets.

@shubhnik
Last active November 9, 2017 16:23
Show Gist options
  • Save shubhnik/67f58f9c384d6606a9f08733069027d4 to your computer and use it in GitHub Desktop.
Save shubhnik/67f58f9c384d6606a9f08733069027d4 to your computer and use it in GitHub Desktop.
// Our Navigator:
const AppNavigator = StackNavigator({
login: {
screen: Login
},
screen1: {
screen: Screen1
},
screen2: {
screen: Logout
}
});
// Suppose the current navigation state of the Navigator is:
currentState = {
index: 1, // represents the current screen from routes array, routes[1]
routes: [
{
routeName:"login",
key:"123456",
},
{
routeName:"screen1",
key:"100000"
}
]
}
// Now we want to navigate to screen2, first get the action needed to naivigate to screen2
const ActionForScreen2 = AppNavigator.router.getActionForPathAndParams(
"screen2"
);
// Now we will get the new state for the navigator using ActionForScreen2 and currentState
const NewStateOfNavigator = AppNavigator.router.getStateForAction(ActionForScreen2, currentState)
// The new updated state of the navigator, given the action and currentState:
console.log(JSON.stringify(NewStateOfNavigator))
// The new updated navigation state, We will see further on how to pass this state to Navigator.
/*
NewStateOfNavigator = {
index: 2, // represents the current screen from routes array, routes[2]
routes: [
{
routeName:"login",
key:"123456",
},
{
routeName:"screen1",
key:"100000"
},
{
routeName:"screen2",
key:"7268828"
}
]
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment