From 276fb8f7b39214c3bd78bad485160f53810151a7 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Sat, 24 Feb 2018 21:08:14 +0100 Subject: [PATCH] remove support for deprecated navigation actions (#3595) * remove support for deprecated navigation actions * remove deprecated action from flow definitions --- flow/react-navigation.js | 59 +---------------------- src/NavigationActions.js | 56 --------------------- src/createNavigationContainer.js | 3 +- src/routers/__tests__/StackRouter-test.js | 34 ------------- src/routers/__tests__/TabRouter-test.js | 23 --------- 5 files changed, 2 insertions(+), 173 deletions(-) diff --git a/flow/react-navigation.js b/flow/react-navigation.js index b6c2de7..1d5d8df 100644 --- a/flow/react-navigation.js +++ b/flow/react-navigation.js @@ -71,25 +71,11 @@ declare module 'react-navigation' { key?: string, |}; - declare type DeprecatedNavigationNavigateAction = {| - type: 'Navigate', - routeName: string, - params?: NavigationParams, - - // The action to run inside the sub-router - action?: NavigationNavigateAction | DeprecatedNavigationNavigateAction, - |}; - declare export type NavigationBackAction = {| type: 'Navigation/BACK', key?: ?string, |}; - declare type DeprecatedNavigationBackAction = {| - type: 'Back', - key?: ?string, - |}; - declare export type NavigationSetParamsAction = {| type: 'Navigation/SET_PARAMS', @@ -100,26 +86,11 @@ declare module 'react-navigation' { params: NavigationParams, |}; - declare type DeprecatedNavigationSetParamsAction = {| - type: 'SetParams', - - // The key of the route where the params should be set - key: string, - - // The new params to merge into the existing route params - params: NavigationParams, - |}; - declare export type NavigationInitAction = {| type: 'Navigation/INIT', params?: NavigationParams, |}; - declare type DeprecatedNavigationInitAction = {| - type: 'Init', - params?: NavigationParams, - |}; - declare export type NavigationResetAction = {| type: 'Navigation/RESET', index: number, @@ -127,25 +98,11 @@ declare module 'react-navigation' { actions: Array, |}; - declare type DeprecatedNavigationResetAction = {| - type: 'Reset', - index: number, - key?: ?string, - actions: Array< - NavigationNavigateAction | DeprecatedNavigationNavigateAction - >, - |}; - declare export type NavigationUriAction = {| type: 'Navigation/URI', uri: string, |}; - declare type DeprecatedNavigationUriAction = {| - type: 'Uri', - uri: string, - |}; - declare export type NavigationReplaceAction = {| +type: 'Navigation/REPLACE', +key: string, @@ -181,17 +138,6 @@ declare module 'react-navigation' { | NavigationSetParamsAction | NavigationResetAction; - declare type DeprecatedNavigationAction = - | DeprecatedNavigationInitAction - | DeprecatedNavigationNavigateAction - | DeprecatedNavigationBackAction - | DeprecatedNavigationSetParamsAction - | DeprecatedNavigationResetAction; - - declare export type PossiblyDeprecatedNavigationAction = - | NavigationAction - | DeprecatedNavigationAction; - /** * NavigationState is a tree of routes for a single navigator, where each * child route may either be a NavigationScreenRoute or a @@ -482,7 +428,7 @@ declare module 'react-navigation' { */ declare export type NavigationDispatch = ( - action: PossiblyDeprecatedNavigationAction + action: NavigationAction ) => boolean; declare export type NavigationProp = { @@ -789,9 +735,6 @@ declare module 'react-navigation' { (payload: { uri: string }): NavigationUriAction, toString: () => string, }, - mapDeprecatedActionAndWarn: ( - action: PossiblyDeprecatedNavigationAction - ) => NavigationAction, }; declare type _RouterProp = { diff --git a/src/NavigationActions.js b/src/NavigationActions.js index 21a2b4d..cff81a9 100644 --- a/src/NavigationActions.js +++ b/src/NavigationActions.js @@ -106,59 +106,6 @@ const completeTransition = createAction(COMPLETE_TRANSITION, payload => ({ key: payload && payload.key, })); -const mapDeprecatedNavigateAction = action => { - if (action.type === 'Navigate') { - const payload = { - routeName: action.routeName, - params: action.params, - }; - if (action.action) { - payload.action = mapDeprecatedNavigateAction(action.action); - } - return navigate(payload); - } - return action; -}; - -const mapDeprecatedAction = action => { - if (action.type === 'Back') { - return back(action); - } else if (action.type === 'Init') { - return init(action); - } else if (action.type === 'Navigate') { - return mapDeprecatedNavigateAction(action); - } else if (action.type === 'Reset') { - return reset({ - index: action.index, - key: action.key, - actions: action.actions.map(mapDeprecatedNavigateAction), - }); - } else if (action.type === 'SetParams') { - return setParams(action); - } - return action; -}; - -const mapDeprecatedActionAndWarn = action => { - const newAction = mapDeprecatedAction(action); - if (newAction !== action) { - const oldType = action.type; - const newType = newAction.type; - console.warn( - [ - `The action type '${oldType}' has been renamed to '${newType}'.`, - `'${oldType}' will continue to work while in beta but will be removed`, - 'in the first major release. Moving forward, you should use the', - 'action constants and action creators exported by this library in', - "the 'actions' object.", - 'See https://github.com/react-community/react-navigation/pull/120 for', - 'more details.', - ].join(' ') - ); - } - return newAction; -}; - export default { // Action constants BACK, @@ -185,7 +132,4 @@ export default { setParams, uri, completeTransition, - - // TODO: Remove once old actions are deprecated - mapDeprecatedActionAndWarn, }; diff --git a/src/createNavigationContainer.js b/src/createNavigationContainer.js index cea0a02..370275e 100644 --- a/src/createNavigationContainer.js +++ b/src/createNavigationContainer.js @@ -166,8 +166,7 @@ export default function createNavigationContainer(Component) { // Per-tick temporary storage for state.nav - dispatch = inputAction => { - const action = NavigationActions.mapDeprecatedActionAndWarn(inputAction); + dispatch = action => { if (!this._isStateful()) { return false; } diff --git a/src/routers/__tests__/StackRouter-test.js b/src/routers/__tests__/StackRouter-test.js index 0bb4596..751f225 100644 --- a/src/routers/__tests__/StackRouter-test.js +++ b/src/routers/__tests__/StackRouter-test.js @@ -1506,40 +1506,6 @@ describe('StackRouter', () => { } }); - test('Maps old actions (uses "Handles the reset action" test)', () => { - global.console.warn = jest.fn(); - const router = StackRouter({ - Foo: { - screen: () =>
, - }, - Bar: { - screen: () =>
, - }, - }); - const initAction = NavigationActions.mapDeprecatedActionAndWarn({ - type: 'Init', - }); - const state = router.getStateForAction(initAction); - const resetAction = NavigationActions.mapDeprecatedActionAndWarn({ - type: 'Reset', - actions: [ - { type: 'Navigate', routeName: 'Foo', params: { bar: '42' } }, - { type: 'Navigate', routeName: 'Bar' }, - ], - index: 1, - }); - const state2 = router.getStateForAction(resetAction, state); - expect(state2 && state2.index).toEqual(1); - expect(state2 && state2.routes[0].params).toEqual({ bar: '42' }); - expect(state2 && state2.routes[0].routeName).toEqual('Foo'); - expect(state2 && state2.routes[1].routeName).toEqual('Bar'); - expect(console.warn).toBeCalledWith( - expect.stringContaining( - "The action type 'Init' has been renamed to 'Navigation/INIT'" - ) - ); - }); - test('URI encoded string get passed to deep link', () => { const uri = 'people/2018%2F02%2F07'; const action = TestStackRouter.getActionForPathAndParams(uri); diff --git a/src/routers/__tests__/TabRouter-test.js b/src/routers/__tests__/TabRouter-test.js index 92dcd74..586568b 100644 --- a/src/routers/__tests__/TabRouter-test.js +++ b/src/routers/__tests__/TabRouter-test.js @@ -593,29 +593,6 @@ describe('TabRouter', () => { expect(path).toEqual('f/Baz'); }); - test('Maps old actions (uses "getStateForAction returns null when navigating to same tab" test)', () => { - global.console.warn = jest.fn(); - const router = TabRouter( - { Foo: BareLeafRouteConfig, Bar: BareLeafRouteConfig }, - { initialRouteName: 'Bar' } - ); - const initAction = NavigationActions.mapDeprecatedActionAndWarn({ - type: 'Init', - }); - const state = router.getStateForAction(initAction); - const navigateAction = NavigationActions.mapDeprecatedActionAndWarn({ - type: 'Navigate', - routeName: 'Bar', - }); - const state2 = router.getStateForAction(navigateAction, state); - expect(state2).toEqual(null); - expect(console.warn).toBeCalledWith( - expect.stringContaining( - "The action type 'Init' has been renamed to 'Navigation/INIT'" - ) - ); - }); - test('Can navigate to other tab (no router) with params', () => { const ScreenA = () =>
; const ScreenB = () =>
;