mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 22:42:13 +08:00
Add sub-reducer support to NavigationStackReducer
Summary: Revise APIs of reducers, and ensure the stack reducer can support sub-reducers Reviewed By: javache Differential Revision: D2959915 fb-gh-sync-id: 20b28b9ead7ace3373489a806486999048d32aef shipit-source-id: 20b28b9ead7ace3373489a806486999048d32aef
This commit is contained in:
committed by
facebook-github-bot-6
parent
876ecb291f
commit
dcb68db758
@@ -36,13 +36,20 @@ export type UIExplorerNavigationState = {
|
||||
};
|
||||
|
||||
const UIExplorerStackReducer = StackReducer({
|
||||
key: 'UIExplorerMainStack',
|
||||
initialStates: [
|
||||
{key: 'AppList'},
|
||||
],
|
||||
initialIndex: 0,
|
||||
matchAction: action => action.openExample && !!UIExplorerList.Modules[action.openExample],
|
||||
actionStateMap: action => ({ key: action.openExample, }),
|
||||
getPushedReducerForAction: (action) => {
|
||||
if (action.type === 'UIExplorerExampleAction' && UIExplorerList.Modules[action.openExample]) {
|
||||
return (state) => state || {key: action.openExample};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
getReducerForState: (initialState) => (state) => state || initialState,
|
||||
initialState: {
|
||||
key: 'UIExplorerMainStack',
|
||||
index: 0,
|
||||
children: [
|
||||
{key: 'AppList'},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
function UIExplorerNavigationReducer(lastState: ?UIExplorerNavigationState, action: any): UIExplorerNavigationState {
|
||||
@@ -86,7 +93,7 @@ function UIExplorerNavigationReducer(lastState: ?UIExplorerNavigationState, acti
|
||||
if (newStack !== lastState.stack) {
|
||||
return {
|
||||
externalExample: null,
|
||||
stack: UIExplorerStackReducer(null, action),
|
||||
stack: newStack,
|
||||
}
|
||||
}
|
||||
return lastState;
|
||||
|
||||
Reference in New Issue
Block a user