Search code examples
react-nativereact-native-navigationwix-react-native-navigation

How to get current routes size of wix/react-native-navigation?


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"


Solution

  • 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