react-native-router-flux物理返回键

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;
}

 

 



猜你喜欢

转载自www.cnblogs.com/lude1994/p/11185286.html
0条评论
添加一条新回复