简体   繁体   English

如何隐藏特定屏幕上的底部标签栏(react-navigation 3.x)

[英]How can I hide the bottom tab bar on a specific screen (react-navigation 3.x)

I used the createBottomTabNavigator, but I can't hide the bottom app bar on a specific screen我使用了 createBottomTabNavigator,但无法隐藏特定屏幕上的底部应用栏

const StackHome = createStackNavigator(
  {
    Home: Home,
    Autor: Autor,
    Publicacion: Publicacion,
    Comentarios: {
      screen: Comentarios,
      navigationOptions:{
        // this should do the work, but it doesn't
        tabBarVisible: false
      }
    }
  }
);

Finally I got a solution that works, the component would be like this最后我得到了一个有效的解决方案,组件将是这样的

import { createStackNavigator } from "react-navigation";
import Home from "./Home";
import Autor from "./Profile";
import Publicacion from "./Publicacion";
import Comentarios from "./Comentarios";

const StackHome = createStackNavigator({
  Home: Home,
  Autor: Autor,
  Publicacion: Publicacion,
  Comentarios: Comentarios
});

// This does the trick
StackHome.navigationOptions = ({ navigation }) => {
  let tabBarVisible;
  if (navigation.state.routes.length > 1) {
    navigation.state.routes.map(route => {
      if (route.routeName === "Comentarios") {
        tabBarVisible = false;
      } else {
        tabBarVisible = true;
      }
    });
  }

  return {
    tabBarVisible
  };
};

export default StackHome;

Nope, it should not... you are hidint the tab bar ... in a stacknavigator... you can do something similar to this .不,它不应该......你是hidint标签栏......在stacknavigator ...你可以做类似的东西这个 but i don't know how you would hide it on one screen但我不知道你会如何将它隐藏在一个屏幕上

const StackHome = createStackNavigator(
  {
    Home: Home,
    Autor: Autor,
    Publicacion: Publicacion,
    Comentarios: Comentarios
  }
);
StackHome navigationOptions = ({ navigation }) => {
  let tabBarVisible = true;

  if (navigation.state.index > 0) {
    tabBarVisible = false;
  }

  return {
    tabBarVisible,
  };
};
const routesWithNoTabNavigator = ['nameOfYourRoute', 'nameOfYourOtherRoute'];

<yourStackHere>.navigationOptions = ({ navigation }) => {
  let tabBarVisible = true;
  const currentRoute = 
        navigation.state.routes[navigation.state.routes.length -1].routeName;
  if(routesWithNoTabNavigator.includes(currentRoute)) {
      tabBarVisible = false;
  }

  return {
   tabBarVisible,
  };
};

if your screen is also nested stack navigation and the parent is a bottom navigation, there is a navigation prop on options function you can use.如果您的屏幕也是嵌套的堆栈导航并且父级是底部导航,则您可以使用选项功能上的导航道具。 eg:例如:

const BottomTab = createBottomTabNavigator();

const Home = () => (
  <BottomTab.Navigator
    initialRouteName="Explore"
    tabBarOptions={{
      activeTintColor: "#00B0F0",
    }}
  >
    <BottomTab.Screen
      name="Explore"
      component={Explore}
      options={({ navigation }) => {
        const { routes, index } = navigation.dangerouslyGetState();
        const { state: exploreState } = routes[index];
        let tabBarVisible = true;
        if (exploreState) {
          const { routes: exploreRoutes, index: exploreIndex } = exploreState;
          const exploreActiveRoute = exploreRoutes[exploreIndex];
          if (exploreActiveRoute.name === "RewardDetail") tabBarVisible = false;
        }
        return {
          tabBarVisible,
          title: "Explore",
          tabBarLabel: "Explore",
          tabBarIcon: ({ color, size }) => (
            <AntDesign name="search1" color={color} size={size} />
          ),
        };
      }}
    />

note that you will have to use if conditions there as props are not present when not activated, just simply do as my example.请注意,您将不得不使用 if 条件,因为在未激活时不存在道具,只需按照我的示例进行操作即可。 There is also a suggestion from the documentation: https://reactnavigation.org/docs/hiding-tabbar-in-screens/ personally i would do that if there's no option for tabBarVisible usage.文档中还有一个建议: https ://reactnavigation.org/docs/hiding-tabbar-in-screens/ 如果没有 tabBarVisible 使用选项,我个人会这样做。

Do like this:这样做:

if(navigation.state.routes[navigation.state.index].routeName == "Comentarios"){
tabBarVisible = false;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用时如何从底部标签栏隐藏“SPECIFIC TAB BAR ITEM”:@react-navigation/bottom-tabs - How to hide a "SPECIFIC TAB BAR ITEM" from a bottom tab bar when using: @react-navigation/bottom-tabs 如何在stackNavigator内部的屏幕中隐藏底部栏 - how to hide bottom bar from in a screen inside stackNavigator react-navigation 如何在本机反应中隐藏特定屏幕上的底部导航栏? - How to hide bottom navigation bar on a specific screen in react native? 我如何知道我是否已经使用选项卡导航(反应导航)离开了屏幕? - How can I know if I leave the screen already with tab navigation (react-navigation)? 如何在反应导航中有条件地隐藏 Tab? - How to hide Tab conditionally in react-navigation? 如何使底部标签栏仅出现在 react-navigation 中嵌套堆栈的默认屏幕上? - How to make bottom tab bar appear only on default screens of nested stacks in react-navigation? 如何使用“@react-navigation/bottom-tabs”在 Tab.Screen 左侧添加 header - How to add header left on Tab.Screen using "@react-navigation/bottom-tabs" 如何在导航版本 6 中隐藏特定屏幕中的标签栏 - How hide tab bar in specific screen in navigation version 6 如何在底部选项卡导航器 react-navigation 中卸载非活动屏幕? - How to unmount inactive screens in bottom tab navigator react-navigation? 如何在React-Navigation中单击Bottom Tab Navigator打开DrawerNavigator? - How do i open DrawerNavigator upon clicking Bottom Tab Navigator in React-Navigation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM