react-navigation / rfcs

RFCs for changes to React Navigation
Other
88 stars 16 forks source link

Improve and Simplify the API for resetting the navigation state #50

Closed iMerica closed 4 years ago

iMerica commented 6 years ago

This is a very clunky API for resetting the stack state:

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

It would be great if we could do something like this instead:

this.props.navigation.navigate('ReportHome').then(() => {
  this.props.navigation.reset()
})

This way after you've gone back to the home screen, all the stacks are globally reset and when you click on a tab again, it won't take you to where you left off.

satya164 commented 4 years ago

Closing since React Navigation 5 implements a simpler reset, i.e. just pass the new state to use:

navigation.reset(newState)