0
Hello, there is 1 week that I am trying to find this problem and I can not solve... I have an application that at a certain time opens a modal that overlaps the main screen. Here are my codes...
Main Screen (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’m on any screen and try to use the feature BackHandler
It works perfectly by changing the state of my Redux and (in the case of this screen) opening my modal. The problem is, when I open this modal, the back button stops working...
I tried to add the event again inside the modal but without success... I even thought that the modal could be interfering in the backbutton, being on top of somehow and nothing... I also tried to add the event of going back to the view that represents my fashionBackdrop and still nothing...
What I need to do so I can use the Backbutton inside a <Modal/>
with React Native?
EDIT
The problem was even mentioned here:
Does anyone have any idea how to solve this?
The problem is that the modal itself brakes the resource of the
hardwareBackPress
... I discovered this after a lot of reading and finding this information in the documentation. so I had to take my modal and turn it into a component that appears based on a state of Redux...– LeandroLuk