mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
feat: let child navigators handle actions from parent
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
This commit is contained in:
committed by
satyajit.happy
parent
f383d131d9
commit
ea8655252d
@@ -211,6 +211,35 @@ const StackRouter: Router<CommonAction | Action> = {
|
||||
}
|
||||
},
|
||||
|
||||
getStateForChildUpdate(state, { update, focus, key }) {
|
||||
const index = state.routes.findIndex(r => r.key === key);
|
||||
|
||||
if (index === -1) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
index: focus ? index : state.index,
|
||||
routes: focus
|
||||
? [
|
||||
...state.routes.slice(0, index),
|
||||
{ ...state.routes[index], state: update },
|
||||
]
|
||||
: state.routes.map((route, i) =>
|
||||
i === index ? { ...route, state: update } : route
|
||||
),
|
||||
};
|
||||
},
|
||||
|
||||
shouldActionPropagateToChildren(action) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
shouldActionChangeFocus(action) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
actionCreators: {
|
||||
push(name: string, params?: object) {
|
||||
return { type: 'PUSH', payload: { name, params } };
|
||||
|
||||
Reference in New Issue
Block a user