简体   繁体   English

底部选项卡导航器上的 expo 图标未显示

[英]expo icons on the bottom tab navigator are not showing

I'm currently doing a react-native course and I started implementing my own code for the styling part.我目前正在学习 react-native 课程,并开始为样式部分实现自己的代码。 I have an issue with icons not showing and I can't seem to find a problem.我有一个图标不显示的问题,我似乎找不到问题。 I have been trying to implement the icon on the bookcase tab, but it doesn't appear on it, and also I don't get an error message on the expo.我一直在尝试实现书柜选项卡上的图标,但它没有出现在上面,而且我在 expo 上也没有收到错误消息。

import React from 'react';
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createAppContainer, createSwitchNavigator} from 'react-navigation';
import { View, StyleSheet } from 'react-native';
import { Text, Button, Input } from 'react-native-elements';
import {createStackNavigator} from 'react-navigation-stack';
import { Ionicons } from '@expo/vector-icons';


const switchNavigator = createSwitchNavigator({
ResolveAuth: ResolveAuthScreen,
loginFlow: createStackNavigator ({
  Signin: signin,
  Signup: signup,
}),

mainFlow: createBottomTabNavigator({
  Bookcase: bookcase,
  Explore: explore,
  Profile: profile
}, {
  tabBarOptions: {
    activeTintColor: 'red',
    inactiveTintColor: 'grey',
    showIcon: true,
  }},
    {
      Bookcase:{
        screen:bookcase,
        navigationOptions:{
          tabBarLabel:'Bookcase',
          tabBarIcon:({ tintColor })=>(
            <Ionicons name="ios-home" color={tintColor} size={2}/>
          )
        }
      }

  }
  )

});

const App = createAppContainer(switchNavigator)

export default () => {
  return (
    <AuthProvider>
      <App ref ={(navigator) => {setNavigator(navigator)}} />
    </AuthProvider>
  );
};

If you are using react-navigation v5, then is preferred way to implement bottomStackNavigation.如果您使用的是 react-navigation v5,那么是实现 bottomStackNavigation 的首选方式。 This code will render icons and its color according to active as well as inactive state.此代码将根据活动和非活动 state 呈现图标及其颜色。 You have to pass options property to individual screen tab in react-navigation v5.您必须将选项属性传递给 react-navigation v5 中的单个屏幕选项卡。

const BottomNavigator = () => {
  const BottomNavigation = createBottomTabNavigator();

  return (
    <BottomNavigation.Navigator>
      <BottomNavigation.Screen
        name="Home"
        component={HomeStack}
        options={{
          tabBarIcon: ({ color, size }) => (
            <MaterialCommunityIcons name="home" color={color} size={size} />
          ),
        }}
      />
      <BottomNavigation.Screen
        name="Exam"
        component={ExamStack}
        options={{
          tabBarIcon: ({ color, size }) => (
            <MaterialCommunityIcons name="book" color={color} size={size} />
          ),
        }}
      />
    </BottomNavigation.Navigator>
  );
};


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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM