0

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"

  • do you try this ? https://wix.github.io/react-native-navigation/#/docs/topBar-buttons?id=handling-button-press-events or this https://github.com/wix/react-native-navigation/issues/4776#issuecomment-481996489 – Maleking Dec 11 '19 at 12:50
  • yes, but for some reason, navigationButtonPressed() isn't called on hardwareBackButton pressed https://github.com/wix/react-native-navigation/issues/4231 – Deyan Denchev Dec 11 '19 at 13:56

1 Answers1

0

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