React Native - Reset child stackNavigator to initial screen onPress of parent tabNavigator

不羁的心 提交于 2019-12-10 17:10:44

问题


I have a simple navigation structure set up with 4 primary screens that the user navigates between using react-navigation/TabNavigator. Within each of those primary screens the user can navigate to the secondary screen using react-navigation/StackNavigator. The secondary screen is the same component for all 4 primary screens, as the content is loaded dynamically depending on which is selected using redux to change the state of the content.

You can see the structure in the diagram below.

The problem I am having is once the secondary screen is called from tab1(for example) the secondary screen rolls into place with content relevant to tab1. If the user then navigates to tab2 and calls the secondary screen, it again rolls into place with content relevant to tab2. This is all fine however if the user then navigates back to tab1 the secondary screen is still in place, this time with the content relevant to tab2 as they have changed the state in the previous tab.

To cut a long story short I'm trying to reset the individual stacks of each primary screen if the user interacts with the TabNavigator at anytime. I'm struggling to see how I can initiate a function from the child stack components by triggering an event in the parent tab component.

Hope that makes sense to people.

来源:https://stackoverflow.com/questions/44830823/react-native-reset-child-stacknavigator-to-initial-screen-onpress-of-parent-ta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!