Created
January 21, 2019 06:54
-
-
Save DeVoresyah/cf5d43a487378a113f163d08ef4eb924 to your computer and use it in GitHub Desktop.
#ask react navigation
This file contains hidden or 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
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