Closed romaricpascal closed 4 years ago
cc @ericvicenti
Hey folks, what if we added the following two new features:
initialAction
prop on the app container to customize the initial actionSET_STATE
action that allows you to set the whole navigation state of the navigator, implemented in the routers' getStateForAction
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: [ {...}, {...} ]
})}
/>
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 :)
React Navigation 5 accepts an initialState
prop which should address this.
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:
react-navigation
could provide deep-linking and async-storage helpers for thatcomponentDidMount
of the class generated bycreateAppContainer
and providing a "last one wins" list ofnav => Promise<nav>
function that would update the nav.Does that sound a useful addition?