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
@@ -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