【问题标题】:I can't hide the tabbar completely, the add button in the middle will show我无法完全隐藏标签栏,中间的添加按钮会显示
【发布时间】:2021-04-20 08:54:17
【问题描述】:

当我在特定屏幕中使用 tabBarVisible 隐藏标签栏时,中间按钮的上半部分仍然可见(红线上方),有什么想法可以隐藏它吗?

我正在使用 react-navigation v5

const StackNav = (props: any) => {

  React.useLayoutEffect(() => {
    routes.includes(name) 
               ? navigation.setOptions({tabBarVisible: false;})
               : navigation.setOptions({tabBarVisible: true;})
  }, [navigation, route]);

  return (
    <Stack.Navigator>
      <Stack.Screen name="home" component={HomeScreen} />
      <Stack.Screen name="food" component={FoodScreen} />
      <Stack.Screen name="review" component={ReviewScreen} />
    </Stack.Navigator>
  );
};

因此,BottomTab 导航包装了包含应用程序所有屏幕的 StackNav

const BottomTab = () => {
  const Tab = createBottomTabNavigator();

  return (
    <Tab.Navigator
      screenOptions={({route}) => ({
        tabBarIcon: ({focused}) => {
          return <Tab focused={focused} />;
        },
      })}
      >
      <Tab.Screen name="profile" component={StackNav} />
      <Tab.Screen name="story" component={StackNav} />
    </Tab.Navigator>
  );
};

【问题讨论】:

  • 是tabBar的中间按钮部分吗?它是否比实际的 tabBar 高度大?
  • @Krismu 是的,它是 tabBar 的一部分,这只是可视化,因为我无法发布它的外观的实际图像,至于高度不,它不大于 tabBar 的高度,但是用于视觉目的的中间按钮必须像这样显示,所以按钮的上半部分在 tabBar 之外。
  • 你能提供你的导航结构的代码和你正在使用的 react-navigation 的版本吗?
  • @krismu 这里的代码都可以工作,所以如果你没有在某处看到声明或导入的变量,请忽略,因为我必须删除一些代码以便我可以在这里发布编辑

标签: react-native react-navigation react-navigation-bottom-tab


【解决方案1】:

React-navigation 不推荐使用tabBarVisible 选项。解决您的问题,您可以use this workflow to hide the tabBar properly

原理很简单,就是由父级使用Stack.NavigatorTab.Navigator中取出不需要tabBar的屏幕。

我将它用于我自己的应用程序using the same tabBar UI as you,它运行良好。

【讨论】:

  • 我希望有一种方法不会改变我拥有的导航结构,因为我之前正在阅读这个文档,所以我需要重新考虑不改变当前结构的决定吗?跨度>
  • 我觉得你应该试试,这不是一个大的返工!只需在包含论文屏幕和BottomTab 的父Stack.Navigator 中取出您不希望tabBar 的屏幕。它不应该改变您应用的其余部分(导航将保持不变)
猜你喜欢
  • 2011-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 2023-03-09
  • 1970-01-01
相关资源
最近更新 更多