Sunday 28 May 2017

Dispatch from one nested navigator to another with react-navigation

I want to send the user from a screen in one StackNavigator to another screen in another StackNavigator, both nested in a TabNavigator.

So if I have my TabNavigator as

const MainNavigator = TabNavigator({
  FirstTab: { screen: StackNavigator1 },
  SecondTab: { screen: StackNavigator2 },
});

and StackNavigator1 has a screen ScreenA

const StackNavigator1 = StackNavigator({
  ScreenA: { screen: ScreenA },
  ScreenB: { screen: ScreenB },
});

and StackNavigator2 has a screen ScreenC

const StackNavigator2 = StackNavigator({
  ScreenC: { screen: ScreenC },
  ScreenD: { screen: ScreenD },
});

I want to send the user from ScreenA to ScreenC.

I guess I should use something like

const resetAction = NavigationActions.reset({
  index: 0,
  actions: [NavigationActions.navigate({ routeName: 'ScreenC' })],
});
this.props.navigation.dispatch(resetAction);

but I afraid ScreenA in StackNavigator1 doesn't know about ScreenC in StackNavigator2, so do I need to use react-redux?



via Jamgreen

No comments:

Post a Comment