react-navigation / rfcs

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

Expose logic for initializing state of createAppContainer #71

Closed romaricpascal closed 4 years ago

romaricpascal commented 5 years ago

At the moment, the logic behind the initialization of the nav state in createAppContainer is completely inaccessible from the outside. If the state has to be inferred from something else than AsyncStorage (or not be persisted as things go) or a deep link, it makes it hacky to set that initial state.

I've had two main use case for that:

I could see two ways of going through this:

<MyAppContainer initialNavState={{/* routename and params */}} />
<MyAppContainer initializeNav={[fromStorage,fromDeepLink,fromNotification,fromLogin]} />

Does that sound a useful addition?

brentvatne commented 5 years ago

cc @ericvicenti

ericvicenti commented 5 years ago

Hey folks, what if we added the following two new features:

So, if you have an initial route you want to show, you could mount the app container with the following:

<MyAppContainer
  initialAction={NavigationActions.navigate({ routeName: 'SomeRoute' })}
/>

Or if you want to launch with a particular navigation state:

<MyAppContainer
  initialAction={NavigationActions.setState({
    index: 1,
    routes: [ {...}, {...} ]
  })}
/>
romaricpascal commented 5 years ago

This sounds great! That would leave plenty of flexibility for the app to configure the initial state however it needs.

Cheers for having considered this RFC :)

satya164 commented 4 years ago

React Navigation 5 accepts an initialState prop which should address this.