tabBar.js 1.37 KB
'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;
}