Skip to content

Instantly share code, notes, and snippets.

@vikas5914 vikas5914/index.js
Created Feb 4, 2019

Embed
What would you like to do?
Exit App in React Navigation
const AppNavigator = createStackNavigator(
{
Screen: Screen,
Login: Login,
Intro: Intro,
},
{
initialRouteName: 'Screen',
transitionConfig,
navigationOptions: {
gesturesEnabled: false
}
}
)
const defaultGetStateForAction = AppNavigator.router.getStateForAction
AppNavigator.router.getStateForAction = (action, state) => {
if (state &&
action.type === NavigationActions.BACK &&
(
state.routes[state.index].routeName === 'Intro' ||
state.routes[state.index].routeName === 'Home' ||
state.routes[state.index].routeName === 'Login'
)
) {
BackHandler.exitApp()
return null
}
return defaultGetStateForAction(action, state)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.