Fix setParams with nested routers (#929)

This fixes the setParams problem with:
https://github.com/react-community/react-navigation/pull/789
This commit is contained in:
taiki-t
2017-04-07 01:22:06 +09:00
parent 356cb0a19f
commit 00fdf7a5ae
2 changed files with 32 additions and 1 deletions

View File

@@ -137,7 +137,6 @@ export default (
const childRoute = state.routes[childIndex];
const childRouter = childRouters[childRoute.routeName];
if (childRouter) {
delete action.key;
const route = childRouter.getStateForAction(action, childRoute);
if (route && route !== childRoute) {
return StateUtils.replaceAt(state, childRoute.key, route);

View File

@@ -467,6 +467,38 @@ describe('StackRouter', () => {
expect(state2 && state2.routes[0].params).toEqual({ name: 'Qux' });
});
test('Handles the setParams action with nested routers', () => {
const ChildNavigator = () => <div />;
const GrandChildNavigator = () => <div />;
GrandChildNavigator.router = StackRouter({
Quux: { screen: () => <div />, },
Corge: { screen: () => <div />, },
});
ChildNavigator.router = TabRouter({
Baz: { screen: GrandChildNavigator, },
Qux: { screen: () => <div />, },
});
const router = StackRouter({
Foo: { screen: ChildNavigator, },
Bar: { screen: () => <div />, },
});
const state = router.getStateForAction({ type: NavigationActions.INIT });
const state2 = router.getStateForAction({
type: NavigationActions.SET_PARAMS,
params: { name: 'foobar' },
key: 'Init',
}, state);
expect(state2 && state2.index).toEqual(0);
/* $FlowFixMe */
expect(state2 && state2.routes[0].routes[0].routes).toEqual([
{
key: 'Init',
routeName: 'Quux',
params: { name: 'foobar' },
},
]);
});
test('Handles the reset action', () => {
const router = StackRouter({
Foo: {