mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-11 09:20:54 +08:00
refactor: add separate method for rehydration and fix types
This commit is contained in:
@@ -55,27 +55,27 @@ export type StackNavigationProp<
|
||||
|
||||
const StackRouter: Router<CommonAction | Action> = {
|
||||
getInitialState({
|
||||
screens,
|
||||
partialState,
|
||||
initialRouteName = Object.keys(screens)[0],
|
||||
routeNames,
|
||||
initialRouteName = routeNames[0],
|
||||
initialParamsList,
|
||||
}) {
|
||||
const routeNames = Object.keys(screens);
|
||||
const index = routeNames.indexOf(initialRouteName);
|
||||
|
||||
return {
|
||||
key: `stack-${shortid()}`,
|
||||
index,
|
||||
routeNames,
|
||||
routes: routeNames.slice(0, index + 1).map(name => ({
|
||||
name,
|
||||
key: `${name}-${shortid()}`,
|
||||
params: initialParamsList[name],
|
||||
})),
|
||||
};
|
||||
},
|
||||
|
||||
getRehydratedState({ routeNames, partialState }) {
|
||||
let state = partialState;
|
||||
|
||||
if (state === undefined) {
|
||||
const index = routeNames.indexOf(initialRouteName);
|
||||
|
||||
state = {
|
||||
index,
|
||||
routes: routeNames.slice(0, index + 1).map(name => ({
|
||||
name,
|
||||
key: `${name}-${shortid()}`,
|
||||
params: screens[name].initialParams,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
if (state.routeNames === undefined || state.key === undefined) {
|
||||
state = {
|
||||
...state,
|
||||
|
||||
Reference in New Issue
Block a user