Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29695

React native navigation v5 android back button handler

$
0
0

I'm using react navigation v5 and I'm trying to make a default android back button handler inside routes.js. Using flux there was backAndroidHandler param which let you do this. My questios is there something i can use in navigation v5.

I know there is https://reactnavigation.org/docs/custom-android-back-button-handling/. But the problem is i don't want to go to every screen and set it.

Current solution is this:

  useEffect(
    useCallback(() => {
      const onAndroidBack = () => {
      };

      BackHandler.addEventListener('hardwareBackPress', onAndroidBack);

      return () =>
        BackHandler.removeEventListener('hardwareBackPress', onAndroidBack);
    }, [])
  );

My question does navigation v5 have some kind of solution for this build in, like flux had? Is there a better way to manage android back button?


Viewing all articles
Browse latest Browse all 29695

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>