对Android应用程序使用react native。使用基于反应本机模态的自定义组件将内容显示在封闭视图上方。
已经尝试对本地Backhandler做出反应
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
this.goBack(); // works best when the goBack is async
return true;
}
Run Code Online (Sandbox Code Playgroud)
或像这样
componentDidMount() {
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
this.goBack(); // works best when the goBack is async
return true;
});
}
componentWillUnmount() {
this.backHandler.remove();
}
Run Code Online (Sandbox Code Playgroud)
这是开放的问题