React Native 底部选项卡导航给出的结果与文档中的结果不同

yqkkidmi  于 2022-12-30  发布在  React
关注(0)|答案(3)|浏览(113)

根据此docexample
得到了这个结果

为什么我总是得到这个结果,用完全相同的代码:

而且在点击上的高亮显示也不起作用。我检查了所有的依赖项和所有的东西,它没有改变。
提示:我的结果和doc显示的一样,为什么不一样?
以下是我的依赖项:

"dependencies": {
    "@react-native-async-storage/async-storage": "^1.17.11",
    "@react-navigation/material-bottom-tabs": "^6.2.10",
    "@react-navigation/native": "^6.1.1",
    "@react-navigation/native-stack": "^6.9.7",
    "@react-navigation/stack": "^6.3.10",
    "react": "18.1.0",
    "react-native": "0.70.6",
    "react-native-gesture-handler": "^2.8.0",
    "react-native-paper": "^5.1.0",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.2",
    "react-native-vector-icons": "^9.2.0"
  },
ubbxdtey

ubbxdtey1#

只需设置您想要的背景颜色:

<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
barStyle={{ backgroundColor: '#694fad' }}
>
 {/* ... */}
</Tab.Navigator>
dgsult0t

dgsult0t2#

您必须对相同的设计做一些更改。启用shiftinglabeled。在每个Tab.screen中添加tabBarColor

function MyTabs() {
  return (
    <Tab.Navigator
      initialRouteName="Feed"
      activeColor="white"
      labelStyle={{ fontSize: 12 }}
      shifting={true}
      labeled={true}
    >
      <Tab.Screen
        name="Feed"
        component={Feed}
        options={{
          tabBarLabel: 'Home',
          tabBarColor: 'red',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="home" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Notifications"
        component={Notifications}
        options={{
          tabBarLabel: 'Updates',
           tabBarColor: 'blue',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="bell" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Profile"
        component={Profile}
        options={{
          tabBarLabel: 'Profile',
          tabBarColor: 'green',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="account" color={color} size={26} />
          ),
        }}
        
      />
    </Tab.Navigator>
  );
}
hkmswyz6

hkmswyz63#

我只是改变了所有的版本,以前和它的工作现在很好:

react-native init datingapp --version 0.68.1

npm install @react-navigation/native@6.0.10
npm install react-native-screens@3.13.1
npm install react-native-safe-area-context@4.3.1
npm install react-native-paper@4.12.1
npm install react-native-vector-icons@9.1.0
npm install @react-navigation/material-bottom-tabs@6.2.1
npm install @react-native-async-storage/async-storage
npm install jotai
npm install @react-navigation/native-stack@6.6.2
npm install react-native-gesture-handler@2.6.1
npm install react-native-safe-area-context@4.3.1
npm install react-native-screens

相关问题