Hello, I'm using a stack in my app and whenever I press the back hardware button on android the app pop to the previous screen.
My issue is that i cannot override this behaviour, I have a BackHandler and a listener which is called whenever i press the hardware back button, but even if i have my own implementation the pop is still happening!
Is there a way to disable the hardware back button ?
Try the following:
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
}
onBackPress = () => {
return true; <---- make sure you return true.
}
@ItsNoHax, I forgot to mention it, but thats what I do and it still doesn't work
@ItsNoHax, i just solve this, the problem was not the return statement from onBackPress. The problem was that my listeners was never removed. Indeed i had multiple listeners for each of my screens and i was removing them in componentWillUnmount lifecycle method. But since I was using a stack the previous screens were never unmount so I had to remove my listener inside componentDidDisappear.
@ItsNoHax , this is awesome.
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
}
onBackPress = () => {
return true; <---- make sure you return true.
}
I want to disable device back button popping, in only one screen
Any idea?
@HappyCodingLover https://wix.github.io/react-native-navigation/api/options-backButton
Most helpful comment
Try the following: