mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-12 09:21:09 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user