Search code examples
react-nativetabsnavigationscreenexit

How can i quit definetively a screen when navigating to another one in react native Tab navigation?


I tried to use this: this.props.navigation.navigatie('Screen') it works but it keep the old screen active in the background. I am using a barcode scanner and i don't want it to drain energy by running in the backgroun.


Solution

  • You need to use the reset method from stack actions :

    documentation here

    import { StackActions, NavigationActions } from 'react-navigation';
    
    const resetAction = StackActions.reset({
      index: 0,
      actions: [NavigationActions.navigate({ routeName: 'Profile' })],
    });
    
    this.props.navigation.dispatch(resetAction);