Resetting the navigation stack for the home screen (React Navigation and React Native)

前端 未结 13 2427
终归单人心
终归单人心 2020-11-29 23:49

I\'ve got a problem with the navigation of React Navigation and React Native. It is about resetting navigation and returning to the home screen.

I\'ve build a StackN

13条回答
  •  清歌不尽
    2020-11-30 00:13

    NavigationActions.reset() seems to be the preferable solution. One issue I ran into with it actions was the tab buttons. Tabs would still show even if I explicitly turned them off in component. If I used navigation.navigate() instead of doing this via reset() it would work fine.

    SomeComponentScreen.navigationOptions = {
      header: null
    };
    

    A workaround for this annoyance that worked for me is to consecutively call multiple navigate statements.

          navigation.goBack();   // this would pop current item in stack
          navigation.navigate({
            routeName: 'SomeOtherComponent'
          });
    

提交回复
热议问题