Skip to content

Instantly share code, notes, and snippets.

@DeVoresyah
Created January 21, 2019 06:54
Show Gist options
  • Save DeVoresyah/cf5d43a487378a113f163d08ef4eb924 to your computer and use it in GitHub Desktop.
Save DeVoresyah/cf5d43a487378a113f163d08ef4eb924 to your computer and use it in GitHub Desktop.
#ask react navigation
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBackButton);
}
componentWillUnmount() {
this._navListener.remove();
BackHandler.removeEventListener('hardwareBackPress', this._handleBackButton);
}
_handleBackButton = () => {
const { click } = this.state;
if (click == 1) {
BackHandler.exitApp()
} else {
ToastAndroid.show('Tap one more to exit', ToastAndroid.SHORT)
this.setState({click:1})
}
setTimeout(() => {
this.setState({click:0})
}, 1500)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment