【问题标题】:How can i quit definetively a screen when navigating to another one in react native Tab navigation?在反应原生选项卡导航中导航到另一个屏幕时,如何明确退出一个屏幕?
【发布时间】:2021-02-28 18:28:16
【问题描述】:

我尝试使用这个:this.props.navigation.navigatie('Screen') 它可以工作,但它会在后台保持旧屏幕处于活动状态。我正在使用条形码扫描仪,我不希望它通过在后台运行来消耗能量。

【问题讨论】:

    标签: react-native tabs navigation screen exit


    【解决方案1】:

    您需要使用堆栈操作中的reset 方法:

    documentation here

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-30
      • 2021-12-03
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2022-10-07
      相关资源
      最近更新 更多