我如何将外部/全局样式应用于React-Navigation底部选项卡

发布于 2025-02-04 07:59:13 字数 1278 浏览 1 评论 0原文

我试图将全局样式应用于React-Native的底部标签导航,但它无法在ScreenOptions Prop中接受。但是当我使用普通的内联样式时,它可以正常工作。请帮忙

export default function CustomBottomTab() {
  return (
    <Tab.Navigator
      screenOptions={{
           tabBarStyle: {styles.customTab} //underlines the dot as an error
}}
    >
      <Tab.Screen
        name='Landing'
        component={HomeScreen}
        options={{
          tabBarIcon: (props) => <AntDesign name='home' size={20} {...props} />,
        }}
      />
      <Tab.Screen
        name='Notifications'
        component={NotifScreen}
        options={{
          tabBarIcon: (props) => (
            <FontAwesome5 name='bell' size={20} {...props} />
          ),
        }}
      />
      <Tab.Screen
        name='Wishlist'
        component={WishScreen}
        options={{
          tabBarIcon: (props) => (
            <Ionicons name='bookmarks-outline' size={20} {...props} />
          ),
        }}
      />
      <Tab.Screen
        name='Messages'
        component={MessagesScreen}
        options={{
          tabBarIcon: (props) => (
            <FontAwesome5 name='comment' size={20} {...props} />
          ),
        }}
      />
    </Tab.Navigator>
  );
}

I tried to apply a global style to a bottom tab navigation in react-native but it can't accept it in the screenOptions prop. But it works fine when I use normal inline styling. Please help

export default function CustomBottomTab() {
  return (
    <Tab.Navigator
      screenOptions={{
           tabBarStyle: {styles.customTab} //underlines the dot as an error
}}
    >
      <Tab.Screen
        name='Landing'
        component={HomeScreen}
        options={{
          tabBarIcon: (props) => <AntDesign name='home' size={20} {...props} />,
        }}
      />
      <Tab.Screen
        name='Notifications'
        component={NotifScreen}
        options={{
          tabBarIcon: (props) => (
            <FontAwesome5 name='bell' size={20} {...props} />
          ),
        }}
      />
      <Tab.Screen
        name='Wishlist'
        component={WishScreen}
        options={{
          tabBarIcon: (props) => (
            <Ionicons name='bookmarks-outline' size={20} {...props} />
          ),
        }}
      />
      <Tab.Screen
        name='Messages'
        component={MessagesScreen}
        options={{
          tabBarIcon: (props) => (
            <FontAwesome5 name='comment' size={20} {...props} />
          ),
        }}
      />
    </Tab.Navigator>
  );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2025-02-11 07:59:13

{styles.customtab}中删除{}。这不是有效的JavaScript语法。

它必须是:

tabBarStyle: styles.customTab

Remove {} from around {styles.customTab}. It's not valid JavaScript syntax.

It needs to be:

tabBarStyle: styles.customTab
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文