Created
February 4, 2019 17:00
-
-
Save vikas5914/208f24ee45116f07a15b93adf0213326 to your computer and use it in GitHub Desktop.
Exit App in React Navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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