feat: add target argument to setParams (#18)

This commit is contained in:
Michał Osadnik
2019-07-20 20:51:03 +01:00
committed by GitHub
parent a64f402ded
commit 1de5494793
15 changed files with 253 additions and 87 deletions

View File

@@ -8,6 +8,7 @@ import {
CommonAction,
ParamListBase,
Router,
BaseRouter,
createNavigator,
} from '../src/index';
@@ -28,9 +29,8 @@ type Action =
| { type: 'POP_TO_TOP' };
export type StackNavigationProp<
ParamList extends ParamListBase,
RouteName extends keyof ParamList = string
> = NavigationProp<ParamList, RouteName> & {
ParamList extends ParamListBase
> = NavigationProp<ParamList> & {
/**
* Push a new screen onto the stack.
*
@@ -55,6 +55,7 @@ export type StackNavigationProp<
};
const StackRouter: Router<CommonAction | Action> = {
...BaseRouter,
getInitialState({
routeNames,
initialRouteName = routeNames[0],
@@ -88,14 +89,6 @@ const StackRouter: Router<CommonAction | Action> = {
return state;
},
getStateForRouteNamesChange(state, { routeNames }) {
return {
...state,
routeNames,
routes: state.routes.filter(route => routeNames.includes(route.name)),
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex(r => r.key === key);
@@ -246,18 +239,10 @@ const StackRouter: Router<CommonAction | Action> = {
}
default:
return null;
return BaseRouter.getStateForAction(state, action);
}
},
shouldActionPropagateToChildren(action) {
return action.type === 'NAVIGATE';
},
shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE';
},
actionCreators: {
push(name: string, params?: object) {
return { type: 'PUSH', payload: { name, params } };