React Native 矢量图标不会显示在 Android 的底部选项卡导航中

Muh*_*kal 2 react-native react-native-vector-icons react-navigation-bottom-tab react-navigation-v5

该图标显示在屏幕/页面中,但不会显示在底部导航中。我尝试过的解决方案:

  • 按照github的安装指南进行操作,我尝试了GRADLEMANUAL选项,但结果相同
  • ./gradlew clean然后尝试过npx react-native run-android,但结果相同
  • npx react-native link react-native-vector-icons 然后尝试过npx react-native run-android,但结果相同

屏幕截图底部导航栏

屏幕截图设置屏幕

它确实出现在屏幕/页面中,如上面的屏幕截图所示,但不会显示在底部导航中。

注意:我已经在模拟器和真实的 Android 设备中进行了测试,但仍然得到相同的结果!

底部选项卡的代码

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import ProductNavigation from './ProductNavigation'
import SettingScreen from '../screen/SettingScreen'



const BottomTab = createBottomTabNavigator();

const BottomTabNav = () => {
return (
    <BottomTab.Navigator>
        <BottomTab.Screen 
        name="Home" 
        component={ProductNavigation} 
        options={{
            tabBarLabel: "Home",
            tabBarIcon:({color, size}) => {
                <Ionicons name="home-outline" color={color} size={size} />
            }}} />

        <BottomTab.Screen 
        name="Settings" 
        component={SettingScreen}
        options={{
            tabBarLabel: "Settings",
            tabBarIcon: ({color, size}) => {
                <Ionicons name="settings-outline" color={color} size={size} 
    />
            
        }}} />
    </BottomTab.Navigator>
   )
  }

 export default BottomTabNav

 const styles = StyleSheet.create({})
Run Code Online (Sandbox Code Playgroud)

另外你能帮忙解释一下为什么底部选项卡会转到下一页吗?我应该在哪里编辑代码,提前谢谢。下面是屏幕截图: 在此输入图像描述

Gur*_*ran 7

实际上问题很简单,你没有从函数中返回任何东西,

    tabBarIcon: ({color, size}) => {
//nothing returned here
                    <Ionicons name="settings-outline" color={color} size={size} 
        />
Run Code Online (Sandbox Code Playgroud)

您必须执行此操作,要么使用如下所示的括号,要么使用代码的 return 语句。

tabBarIcon: ({color, size}) => (
                <Ionicons name="settings-outline" color={color} size={size} 
    />)
Run Code Online (Sandbox Code Playgroud)