From 3e1a722d29da7096d6a837be6607efcd8515f402 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Sat, 17 Mar 2018 16:27:19 -0400 Subject: [PATCH] Fix push action -- regressed when making navigate "less pushy" --- .../src/routers/StackRouter.js | 2 +- .../src/routers/__tests__/StackRouter-test.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-navigation/src/routers/StackRouter.js b/packages/react-navigation/src/routers/StackRouter.js index 7f035d3a..fb802c53 100644 --- a/packages/react-navigation/src/routers/StackRouter.js +++ b/packages/react-navigation/src/routers/StackRouter.js @@ -206,7 +206,7 @@ export default (routeConfigs, stackConfig = {}) => { } }); - if (lastRouteIndex !== -1) { + if (action.type !== NavigationActions.PUSH && lastRouteIndex !== -1) { // If index is unchanged and params are not being set, leave state identity intact if (state.index === lastRouteIndex && !action.params) { return state; diff --git a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js index bae0fba2..31606bbf 100644 --- a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js +++ b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js @@ -684,6 +684,26 @@ describe('StackRouter', () => { }).toThrow(); }); + test('Push adds new routes every time', () => { + const TestRouter = StackRouter({ + foo: { screen: () =>
}, + bar: { screen: () =>
}, + }); + const initState = TestRouter.getStateForAction(NavigationActions.init()); + const pushedState = TestRouter.getStateForAction( + NavigationActions.push({ routeName: 'bar' }), + initState + ); + expect(pushedState.index).toEqual(1); + expect(pushedState.routes[1].routeName).toEqual('bar'); + const secondPushedState = TestRouter.getStateForAction( + NavigationActions.push({ routeName: 'bar' }), + pushedState + ); + expect(secondPushedState.index).toEqual(2); + expect(secondPushedState.routes[2].routeName).toEqual('bar'); + }); + test('Navigate backwards with key removes leading routes', () => { const TestRouter = StackRouter({ foo: { screen: () =>
},