1.引入BackHandler 从react-native中
2.在componentDidMount中添加下面那行监听代码
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
3.在componentWillUnmount添加
componentWillUnmount() {
this.backHandler.remove()
}
4.在handleBackPress函数中写相关返回逻辑
handleBackPress = () => {
Actions.pop(); // 跳转,可以跳转到想去的页面或位置,根据react-native-router-flux组件的方法
console.log("wo handle back press detail")
// //this.goBack(); // works best when the goBack is async
return true;
}