mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 09:17:55 +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
@@ -26,12 +26,21 @@ const {
|
||||
} = NavigationExperimental;
|
||||
const StackReducer = NavigationReducer.StackReducer;
|
||||
|
||||
const NavigationBasicReducer = StackReducer({
|
||||
initialStates: [
|
||||
{key: 'first_page'}
|
||||
],
|
||||
matchAction: action => true,
|
||||
actionStateMap: action => ({key: action}),
|
||||
const NavigationBasicReducer = NavigationReducer.StackReducer({
|
||||
getPushedReducerForAction: (action) => {
|
||||
if (action.type === 'push') {
|
||||
return (state) => state || {key: action.key};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
getReducerForState: (initialState) => (state) => state || initialState,
|
||||
initialState: {
|
||||
key: 'BasicExampleStackKey',
|
||||
index: 0,
|
||||
children: [
|
||||
{key: 'First Route'},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const NavigationBasicExample = React.createClass({
|
||||
@@ -51,13 +60,13 @@ const NavigationBasicExample = React.createClass({
|
||||
<NavigationExampleRow
|
||||
text={`Push page #${navState.children.length}`}
|
||||
onPress={() => {
|
||||
onNavigate('page #' + navState.children.length);
|
||||
onNavigate({ type: 'push', key: 'page #' + navState.children.length });
|
||||
}}
|
||||
/>
|
||||
<NavigationExampleRow
|
||||
text="pop"
|
||||
onPress={() => {
|
||||
onNavigate(StackReducer.PopAction());
|
||||
onNavigate(NavigationRootContainer.getBackAction());
|
||||
}}
|
||||
/>
|
||||
<NavigationExampleRow
|
||||
|
||||
Reference in New Issue
Block a user