From fb5d0ff587063dc5dec1985716375a9721e48c59 Mon Sep 17 00:00:00 2001 From: Hedger Wang Date: Fri, 20 May 2016 18:09:57 -0700 Subject: [PATCH] D3321403 [NavigationExperimental][CleanUp]: Rename `scene.navigationState` to `scene.route`. Summary: [public / experimental API breaking change] The data type of `scene.navigationState` is `NavigationRoute`. Rename `scene.navigationState` to `scene.route` to avoid confusion such as treating `scene.navigationState` as the actual global navigation state (type: NavigationState). Reviewed By: ericvicenti Differential Revision: D3331076 fbshipit-source-id: 3ed989cc8492d398cbeb1b12186459deb261d1fb --- .../NavigationAnimatedExample.js | 6 ++-- .../NavigationCardStackExample.js | 2 +- .../NavigationCompositionExample.js | 2 +- Examples/UIExplorer/UIExplorerApp.ios.js | 4 +-- .../UIExplorer/UIExplorerStateTitleMap.js | 8 ++--- .../NavigationExperimental/NavigationCard.js | 7 ++-- .../NavigationCardStack.js | 2 +- .../NavigationPropTypes.js | 20 ++++++------ .../NavigationTypeDefinition.js | 4 +-- .../Reducer/NavigationScenesReducer.js | 25 ++++++++------- .../__tests__/NavigationScenesReducer-test.js | 32 +++++++++---------- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Examples/UIExplorer/NavigationExperimental/NavigationAnimatedExample.js b/Examples/UIExplorer/NavigationExperimental/NavigationAnimatedExample.js index 4c7c3377c..8764df483 100644 --- a/Examples/UIExplorer/NavigationExperimental/NavigationAnimatedExample.js +++ b/Examples/UIExplorer/NavigationExperimental/NavigationAnimatedExample.js @@ -113,7 +113,7 @@ class NavigationAnimatedExample extends React.Component { _renderTitleComponent(/*NavigationSceneRendererProps*/ props) { return ( - {props.scene.navigationState.key} + {props.scene.route.key} ); } @@ -122,7 +122,7 @@ class NavigationAnimatedExample extends React.Component { return ( ); @@ -132,7 +132,7 @@ class NavigationAnimatedExample extends React.Component { return ( - {stateTypeTitleMap(props.scene.navigationState)} + {stateTypeTitleMap(props.scene.route)} ); } diff --git a/Examples/UIExplorer/UIExplorerApp.ios.js b/Examples/UIExplorer/UIExplorerApp.ios.js index 6739b5645..760a96043 100644 --- a/Examples/UIExplorer/UIExplorerApp.ios.js +++ b/Examples/UIExplorer/UIExplorerApp.ios.js @@ -152,13 +152,13 @@ class UIExplorerApp extends React.Component { _renderTitleComponent(props: NavigationSceneRendererProps): ReactElement { return ( - {UIExplorerStateTitleMap(props.scene.navigationState)} + {UIExplorerStateTitleMap(props.scene.route)} ); } _renderScene(props: NavigationSceneRendererProps): ?ReactElement { - const state = props.scene.navigationState; + const state = props.scene.route; if (state.key === 'AppList') { return ( { static propTypes = { sceneRenderer: PropTypes.func.isRequired, - sceneRendererProps: - PropTypes.shape(NavigationPropTypes.SceneRenderer).isRequired, + sceneRendererProps: NavigationPropTypes.SceneRenderer, }; shouldComponentUpdate(nextProps: SceneViewProps, nextState: any): boolean { return ( - nextProps.sceneRendererProps.scene.navigationState !== - this.props.sceneRendererProps.scene.navigationState + nextProps.sceneRendererProps.scene.route !== + this.props.sceneRendererProps.scene.route ); } diff --git a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js index 4a5353110..1dc535cdd 100644 --- a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js +++ b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStack.js @@ -89,7 +89,7 @@ class NavigationCardStack extends React.Component { static propTypes = { direction: PropTypes.oneOf([Directions.HORIZONTAL, Directions.VERTICAL]), - navigationState: NavigationPropTypes.navigationParentState.isRequired, + navigationState: NavigationPropTypes.navigationState.isRequired, onNavigate: NavigationPropTypes.SceneRendererProps.onNavigate, renderOverlay: PropTypes.func, renderScene: PropTypes.func.isRequired, diff --git a/Libraries/NavigationExperimental/NavigationPropTypes.js b/Libraries/NavigationExperimental/NavigationPropTypes.js index e3e72ec77..9389ac1d6 100644 --- a/Libraries/NavigationExperimental/NavigationPropTypes.js +++ b/Libraries/NavigationExperimental/NavigationPropTypes.js @@ -36,15 +36,15 @@ const action = PropTypes.shape({ const animatedValue = PropTypes.instanceOf(Animated.Value); /* NavigationRoute */ -const navigationState = PropTypes.shape({ +const navigationRoute = PropTypes.shape({ key: PropTypes.string.isRequired, }); -/* NavigationState */ -const navigationParentState = PropTypes.shape({ +/* navigationRoute */ +const navigationState = PropTypes.shape({ index: PropTypes.number.isRequired, key: PropTypes.string.isRequired, - children: PropTypes.arrayOf(navigationState), + children: PropTypes.arrayOf(navigationRoute), }); /* NavigationLayout */ @@ -61,13 +61,13 @@ const scene = PropTypes.shape({ index: PropTypes.number.isRequired, isStale: PropTypes.bool.isRequired, key: PropTypes.string.isRequired, - navigationState, + route: navigationRoute.isRequired, }); /* NavigationSceneRendererProps */ const SceneRendererProps = { layout: layout.isRequired, - navigationState: navigationParentState.isRequired, + navigationState: navigationState.isRequired, onNavigate: PropTypes.func.isRequired, position: animatedValue.isRequired, progress: animatedValue.isRequired, @@ -118,9 +118,9 @@ module.exports = { SceneRendererProps, // propTypes - action, - navigationParentState, - navigationState, - panHandlers, SceneRenderer, + action, + navigationState, + navigationRoute, + panHandlers, }; diff --git a/Libraries/NavigationExperimental/NavigationTypeDefinition.js b/Libraries/NavigationExperimental/NavigationTypeDefinition.js index 056465486..42ef78d5a 100644 --- a/Libraries/NavigationExperimental/NavigationTypeDefinition.js +++ b/Libraries/NavigationExperimental/NavigationTypeDefinition.js @@ -26,8 +26,8 @@ export type NavigationRoute = { }; export type NavigationState = { - index: number, key: string, + index: number, children: Array, }; @@ -45,7 +45,7 @@ export type NavigationScene = { index: number, isStale: boolean, key: string, - navigationState: NavigationRoute, + route: NavigationRoute, }; export type NavigationSceneRendererProps = { diff --git a/Libraries/NavigationExperimental/Reducer/NavigationScenesReducer.js b/Libraries/NavigationExperimental/Reducer/NavigationScenesReducer.js index ca6617c04..80d791cd7 100644 --- a/Libraries/NavigationExperimental/Reducer/NavigationScenesReducer.js +++ b/Libraries/NavigationExperimental/Reducer/NavigationScenesReducer.js @@ -14,8 +14,9 @@ const invariant = require('fbjs/lib/invariant'); import type { - NavigationState, + NavigationRoute, NavigationScene, + NavigationState, } from 'NavigationTypeDefinition'; const SCENE_KEY_PREFIX = 'scene_'; @@ -62,8 +63,8 @@ function areScenesShallowEqual( one.key === two.key && one.index === two.index && one.isStale === two.isStale && - one.navigationState === two.navigationState && - one.navigationState.key === two.navigationState.key + one.route === two.route && + one.route.key === two.route.key ); } @@ -76,9 +77,9 @@ function NavigationScenesReducer( return scenes; } - const prevScenes = new Map(); - const freshScenes = new Map(); - const staleScenes = new Map(); + const prevScenes: Map = new Map(); + const freshScenes: Map = new Map(); + const staleScenes: Map = new Map(); // Populate stale scenes from previous scenes marked as stale. scenes.forEach(scene => { @@ -90,13 +91,13 @@ function NavigationScenesReducer( }); const nextKeys = new Set(); - nextState.children.forEach((navigationState, index) => { - const key = SCENE_KEY_PREFIX + navigationState.key; + nextState.children.forEach((route, index) => { + const key = SCENE_KEY_PREFIX + route.key; const scene = { index, isStale: false, key, - navigationState, + route, }; invariant( !nextKeys.has(key), @@ -115,8 +116,8 @@ function NavigationScenesReducer( if (prevState) { // Look at the previous children and classify any removed scenes as `stale`. - prevState.children.forEach((navigationState, index) => { - const key = SCENE_KEY_PREFIX + navigationState.key; + prevState.children.forEach((route: NavigationRoute, index) => { + const key = SCENE_KEY_PREFIX + route.key; if (freshScenes.has(key)) { return; } @@ -124,7 +125,7 @@ function NavigationScenesReducer( index, isStale: true, key, - navigationState, + route, }); }); } diff --git a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js index 9cced5b71..6d543bdde 100644 --- a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js +++ b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js @@ -17,7 +17,7 @@ const NavigationScenesReducer = require('NavigationScenesReducer'); * Simulate scenes transtion with changes of navigation states. */ function testTransition(states) { - const navigationStates = states.map(keys => { + const routes = states.map(keys => { return { children: keys.map(key => { return { key }; @@ -27,7 +27,7 @@ function testTransition(states) { let scenes = []; let prevState = null; - navigationStates.forEach((nextState) => { + routes.forEach((nextState) => { scenes = NavigationScenesReducer(scenes, nextState, prevState); prevState = nextState; }); @@ -47,7 +47,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': false, 'key': 'scene_1', - 'navigationState': { + 'route': { 'key': '1' }, }, @@ -55,7 +55,7 @@ describe('NavigationScenesReducer', () => { 'index': 1, 'isStale': false, 'key': 'scene_2', - 'navigationState': { + 'route': { 'key': '2' }, }, @@ -74,7 +74,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': false, 'key': 'scene_1', - 'navigationState': { + 'route': { 'key': '1' }, }, @@ -82,7 +82,7 @@ describe('NavigationScenesReducer', () => { 'index': 1, 'isStale': false, 'key': 'scene_2', - 'navigationState': { + 'route': { 'key': '2' }, }, @@ -90,7 +90,7 @@ describe('NavigationScenesReducer', () => { 'index': 2, 'isStale': false, 'key': 'scene_3', - 'navigationState': { + 'route': { 'key': '3' }, }, @@ -109,7 +109,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': false, 'key': 'scene_1', - 'navigationState': { + 'route': { 'key': '1' }, }, @@ -117,7 +117,7 @@ describe('NavigationScenesReducer', () => { 'index': 1, 'isStale': false, 'key': 'scene_2', - 'navigationState': { + 'route': { 'key': '2' }, }, @@ -125,7 +125,7 @@ describe('NavigationScenesReducer', () => { 'index': 2, 'isStale': true, 'key': 'scene_3', - 'navigationState': { + 'route': { 'key': '3' }, }, @@ -143,7 +143,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': true, 'key': 'scene_1', - 'navigationState': { + 'route': { 'key': '1' }, }, @@ -151,7 +151,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': false, 'key': 'scene_3', - 'navigationState': { + 'route': { 'key': '3' }, }, @@ -159,7 +159,7 @@ describe('NavigationScenesReducer', () => { 'index': 1, 'isStale': true, 'key': 'scene_2', - 'navigationState': { + 'route': { 'key': '2' }, }, @@ -178,7 +178,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': true, 'key': 'scene_1', - 'navigationState': { + 'route': { 'key': '1' }, }, @@ -186,7 +186,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': false, 'key': 'scene_2', - 'navigationState': { + 'route': { 'key': '2' }, }, @@ -194,7 +194,7 @@ describe('NavigationScenesReducer', () => { 'index': 0, 'isStale': true, 'key': 'scene_3', - 'navigationState': { + 'route': { 'key': '3' }, },