tabBar.js
1.37 KB
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
40
41
42
43
'use strict';
/******************************
*
* 注意每次更新 react-native-router-flux 版本,
* 都要检查此方法是否需要更新!!!!!!!!!
*
*******************************/
export function shouldShowTabBar(navigationState) {
let index = getSceneIndex(navigationState);
return index == 1; // 只有从home的下一个scene返回至home时才需要显示tab bar
}
export function shouldHideTabBar(navigationState) {
let index = getSceneIndex(navigationState);
return index !== 0; // 非home的scene都需要隐藏tab bar
}
function getSceneIndex(navigationState) {
let {initial, key, parent, name, clone} = navigationState;
let index = 0;
if (initial) {
// 如果是initial是ture的scene,则key的格式是`${position}_${name}`
// 0_Home
index = key.substring(0, 1);
} else {
// 如果是initial是false
// 如果clone是true,则key的格式是`${parent}_${name}_${position}_${name}`
// root_Section_10_Section
// 如果clone是false,则key的格式是`${name}_${position}_${name}`
// Posting_11_Posting
let prefix = clone ? `${parent}_${name}_` : `${name}_`;
let start = prefix.length;
let stop = key.lastIndexOf('_');
index = key.substring(start, stop);
}
console.log(key);
console.log(index);
return index;
}