隐藏 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/