mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
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
This commit is contained in:
committed by
Facebook Github Bot 4
parent
a45d025385
commit
fb5d0ff587
@@ -69,14 +69,13 @@ class SceneView extends React.Component<any, SceneViewProps, any> {
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class NavigationCardStack extends React.Component<DefaultProps, Props, void> {
|
||||
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -26,8 +26,8 @@ export type NavigationRoute = {
|
||||
};
|
||||
|
||||
export type NavigationState = {
|
||||
index: number,
|
||||
key: string,
|
||||
index: number,
|
||||
children: Array<NavigationRoute>,
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ export type NavigationScene = {
|
||||
index: number,
|
||||
isStale: boolean,
|
||||
key: string,
|
||||
navigationState: NavigationRoute,
|
||||
route: NavigationRoute,
|
||||
};
|
||||
|
||||
export type NavigationSceneRendererProps = {
|
||||
|
||||
@@ -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<string, NavigationScene> = new Map();
|
||||
const freshScenes: Map<string, NavigationScene> = new Map();
|
||||
const staleScenes: Map<string, NavigationScene> = 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,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user