Hello, I have been trying for 1 week to find this problem and I can not solve it ... I have an application that, at some point, opens a modal that overlays the main screen. Here are my codes ...
LanListScreen
default class LanListScreen extends React.Component {
render() {
return (
<View>
<HeaderBar />
<SubHeaderBar />
<AddLanModal visible={!!this.props.AddLanIsOpen} />
</View>
)
}
componentWillMount = () => {
BackHandler.addEventListener('hardwareBackPress', () => {
this.props.lanToggleAdd();
return true;
});
}
}
const mstp = state => {
return { AddLanIsOpen: state.lanReducer.AddLanIsOpen }
};
const mdtp = {
lanToggleAdd
}
export default connect(mstp, mdtp)(LanListScreen);
Modal (AddLanModal)
class AddLanModal extends React.Component {
render() {
return (
<Modal
animationType="fade"
transparent={true}
visible={this.props.visible}
onRequestClose={() => null}>
<View>
<View>
<Text>teste</Text>
</View>
</View>
</Modal>
)
}
componentWillMount = () => {
BackHandler.addEventListener('hardwareBackPress', () => {
this.props.lanToggleAdd();
return true;
});
}
}
const styles = { ... }
const mdtp = {
lanToggleAdd
}
export default connect(null, mdtp)(AddLanModal);
My problem is this, when I am in any Screen and I try to use the BackHandler
feature it works perfectly by changing the status of my redux and (in the case of this screen) opening my modal. The problem is that when I open this modal, the back button stops working ...
I tried to add the event again in the modal but without success ... until I thought that the modal could be interfering in the backbutton, being over somehow and nothing ... I also tried to add the event back to the view which represents my modalBackdrop and anyway nothing ...
What do I need to do so I can use the BackButton within a <Modal/>
with React Native?
EDIT
The problem has even been quoted here:
Does anyone have any idea how to solve this?