-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathUtil.js
39 lines (34 loc) · 1.11 KB
/
Util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// searches for the deepest explicitly set value for a key
// in a navigationState tree.
export function deepestExplicitValueForKey(navigationState, key) {
let current;
let selected = navigationState;
while ({}.hasOwnProperty.call(selected, 'children')) {
if (!selected.tabs) {
// for pushed children, iterate through each, recording key value,
// until reaching the selected child
for (let i = 0; i < selected.index; i += 1) {
if (typeof selected.children[i][key] !== 'undefined') {
current = selected.children[i][key];
}
}
}
// set the new selected child and check for a key value
selected = selected.children[selected.index];
if (typeof selected[key] !== 'undefined') {
current = selected[key];
}
}
// fallback to the root key value
if (typeof current === 'undefined') {
current = navigationState[key];
}
return current;
}
export function assert(expr, failDescription) {
if (!expr) {
throw new Error(`[react-native-router-flux] ${failDescription}`);
}
}
export const OnEnter = 'onEnter';
export const OnExit = 'onExit';