隐藏 react-navigation/bottom-tabs

    有时需要在bottom tab中的screen中隐藏tab bar,包括其占用的高度也隐藏。参见:https://medium.com/@indrajit.suryakanta.9/customise-tabbar-in-react-native-bottom-tab-navigator-e2ced7419220
     例如在MedicationsScreen中我的code如下:
           
复制代码
const hideTabBar = () => {
    navigation.getParent()?.setOptions({tabBarStyle: { display: 'none' }});
};
const showTabBar = () => {
    navigation.getParent()?.setOptions({tabBarStyle: { display: 'flex', position: "absolute" }});
};
useEffect(() => {
    // hide the tab bar on mount
    hideTabBar();
    // cleanup tab invisible after unmount
    // cleanup 是必须的,保证退出当前Screen的时候依然显示tab bar
    return () => {
        showTabBar();
    }
}, []);
复制代码
           
    官方的建议是调整 tab 和 stack的位置。https://reactnavigation.org/docs/hiding-tabbar-in-screens/
posted @   saaspeter  阅读(106)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示