Skip to content

Commit 236e449

Browse files
committed
change export/import style for Util
1 parent 26b8b3f commit 236e449

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

src/DefaultRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import TabBar from './TabBar';
2121
import NavBar from './NavBar';
2222
import Actions from './Actions';
23-
import Util from './Util';
23+
import { deepestExplicitValueForKey } from './Util';
2424

2525
const {
2626
AnimatedView: NavigationAnimatedView,
@@ -82,8 +82,8 @@ export default class DefaultRenderer extends Component {
8282
// Since we always need to pass a style for the direction, we can avoid #526
8383
let style;
8484
if (getSceneStyle) {
85-
const hideNavBar = Util.deepestExplicitValueForKey(props.navigationState, 'hideNavBar');
86-
const hideTabBar = Util.deepestExplicitValueForKey(props.navigationState, 'hideTabBar');
85+
const hideNavBar = deepestExplicitValueForKey(props.navigationState, 'hideNavBar');
86+
const hideTabBar = deepestExplicitValueForKey(props.navigationState, 'hideTabBar');
8787
style = getSceneStyle({ ...props, hideNavBar, hideTabBar });
8888
}
8989

@@ -129,7 +129,7 @@ export default class DefaultRenderer extends Component {
129129
selected = selected.children[selected.index];
130130
}
131131

132-
const hideNavBar = Util.deepestExplicitValueForKey(state, 'hideNavBar');
132+
const hideNavBar = deepestExplicitValueForKey(state, 'hideNavBar');
133133
if (hideNavBar) {
134134
return null;
135135
}

src/TabBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View } from 'react-native';
33
import DefaultRenderer from './DefaultRenderer';
44
import Actions from './Actions';
55
import TabNavigator from 'react-native-tab-navigator';
6-
import Util from './Util';
6+
import { deepestExplicitValueForKey } from './Util';
77

88
class TabBar extends Component {
99

@@ -27,7 +27,7 @@ class TabBar extends Component {
2727
render() {
2828
const state = this.props.navigationState;
2929
const selected = state.children[state.index];
30-
const hideTabBar = Util.deepestExplicitValueForKey(state, 'hideTabBar');
30+
const hideTabBar = deepestExplicitValueForKey(state, 'hideTabBar');
3131

3232
const tabBarStyle = {};
3333

src/Util.js

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
export function assert(expr, failDescription) {
2-
if (!expr) {
3-
throw new Error(`[react-native-router-flux] ${failDescription}`);
4-
}
5-
}
1+
// searches for the deepest explicitly set value for a key
2+
// in a navigationState tree.
3+
export function deepestExplicitValueForKey(navigationState, key) {
4+
let current;
5+
let selected = navigationState;
66

7-
export default {
8-
9-
// searches for the deepest explicitly set value for a key
10-
// in a navigationState tree.
11-
deepestExplicitValueForKey(navigationState, key) {
12-
let current;
13-
let selected = navigationState;
14-
15-
while (selected.hasOwnProperty('children')) {
16-
if (!selected.tabs) {
17-
// for pushed children, iterate through each, recording key value,
18-
// until reaching the selected child
19-
for (let i = 0; i < selected.index; i++) {
20-
if (typeof(selected.children[i][key]) !== 'undefined') {
21-
current = selected.children[i][key];
22-
}
7+
while (selected.hasOwnProperty('children')) {
8+
if (!selected.tabs) {
9+
// for pushed children, iterate through each, recording key value,
10+
// until reaching the selected child
11+
for (let i = 0; i < selected.index; i++) {
12+
if (typeof(selected.children[i][key]) !== 'undefined') {
13+
current = selected.children[i][key];
2314
}
2415
}
25-
// set the new selected child and check for a key value
26-
selected = selected.children[selected.index];
27-
if (typeof(selected[key]) !== 'undefined') {
28-
current = selected[key];
29-
}
3016
}
31-
32-
// fallback to the root key value
33-
if (typeof(current) === 'undefined') {
34-
current = navigationState[key];
17+
// set the new selected child and check for a key value
18+
selected = selected.children[selected.index];
19+
if (typeof(selected[key]) !== 'undefined') {
20+
current = selected[key];
3521
}
22+
}
3623

37-
return current;
38-
},
39-
};
24+
// fallback to the root key value
25+
if (typeof(current) === 'undefined') {
26+
current = navigationState[key];
27+
}
28+
29+
return current;
30+
}
4031

4132
export function assert(expr, failDescription) {
4233
if (!expr) {
4334
throw new Error(`[react-native-router-flux] ${failDescription}`);
4435
}
4536
}
37+
38+
export default {
39+
deepestExplicitValueForKey,
40+
assert,
41+
};

0 commit comments

Comments
 (0)