使用react本机用于android应用程序。使用基于本机模式的自定义组件将内容显示在包围视图之上。
已经尝试过响应本机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;
}
或者像这样
componentDidMount() {
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
this.goBack(); // works best when the goBack is async
return true;
});
}
componentWillUnmount() {
this.backHandler.remove();
}
这里是开放的问题
发布于 2019-04-02 15:59:01
不幸的是,这行不通。如果您检查onRequestClose,您将看到您需要在模型上使用文档。BackHandler“只要模态打开,就不会发出...events”。
像这样的东西会有用的:
<Modal
visible={visible}
onRequestClose={() => {
console.log("back");
}}
>
发布于 2022-04-06 20:50:03
对我来说很管用
<Modal isVisible={ProfileImageEditModal}
onRequestClose={() => {
setProfileImageEditModal(false)
}}
/>
https://stackoverflow.com/questions/52932979
复制相似问题