0
votes

I'm trying to handle the back button on android since my React Native app has custom logic on the back button pressed for the root screen...Is there any method like Navigation.getCurrentRoutes() in order to do something like this:

handleBackButton = () => { 
if(Navigation.getCurrentRoutes().size()>1) {
return true; // addEventListener listens for the native hardware back button press and will ignore it
} 
... customLogic
return false; //  will execute the native back press (and exit the app) 
} 

"react-native-navigation": "3.0.0-alpha.2"

1
yes, but for some reason, navigationButtonPressed() isn't called on hardwareBackButton pressed github.com/wix/react-native-navigation/issues/4231Deyan Denchev

1 Answers

0
votes

It turns out that there is not such a method and the two options are: 1) Handle back buttons on your own (overriding) or 2) just add your custom logic into componentWillUnmount() and continue using the native react-native-navigation

options 2 worked for me

reference: https://github.com/wix/react-native-navigation/pull/4226#issuecomment-433683885 https://github.com/wix/react-native-navigation/issues/4231