【问题标题】:Icons are not displaying in BottomTabNavigator in react Native在反应本机中,BottomTabNavigator 中未显示图标
【发布时间】:2019-11-25 16:26:19
【问题描述】:

我一直在研究这个简单的移动应用程序。我试图在底部标签导航而不是标签上显示一些图标,但这些图标没有显示出来。有人可以帮我找出问题所在吗?

我一直在研究这个简单的移动应用程序。我试图在底部标签导航而不是标签上显示一些图标,但这些图标没有显示出来。有人可以帮我找出问题所在吗?

这是我的代码:

import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';

import { Icon } from 'react-native-elements';

// Components
import Home from './src/components/home/Home'
import EventInfo from './src/components/common/eventInfo/EventInfo'
import Profile from './src/components/profile/Profile'
import Browse from './src/components/browse/Browse'
import Activity from './src/components/activity/Activity'

import homeIcon from './src/images/home.png'
import browseIcon from './src/images/home.png'
import activityIcon from './src/images/home.png'
import profileIcon from './src/images/home.png'

import myIcon from './src/images/activity.png';

const HomeStackNavigator = createStackNavigator({
  Home: {
    screen: Home
  },
  EventInfo: {
    screen: EventInfo
  },
},{
  initialRouteName: 'Home', 
})

const BrowseStackNavigator = createStackNavigator({
  Browse: {
    screen: Browse
  },
},{
  initialRouteName: 'Browse', 
})

const ActivityStackNavigator = createStackNavigator({
  Activity: {
    screen: Activity
  },
},{
  initialRouteName: 'Activity', 
})

const ProfileStackNavigator = createStackNavigator({
  Profile: {
    screen: Profile
  },
  EventInfo: {
    screen: EventInfo
  },
},{
  initialRouteName: 'Profile', 
})

const AppNavigator = createBottomTabNavigator({
  Home : HomeStackNavigator,
  Browse: BrowseStackNavigator,
  Activity: ActivityStackNavigator,
  Profile : ProfileStackNavigator,
},{
  initialRouteName:'Profile',
  defaultNavigationOptions: ({ navigation }) => ({
    tabBaricon: ({ focused, horizontal, tintColor }) => {
        return (
          <Image 
            source={myIcon}
            style={{width:30, height:30}} 
          />
        );
    },
  }),
  tabBarOptions: {
  }
}

);

export default createAppContainer(AppNavigator);

【问题讨论】:

    标签: react-native react-navigation react-native-navigation


    【解决方案1】:

    这应该可以解决您的问题。您还应该考虑阅读文档herehere 以更好地理解。

    ...
    
    const AppNavigator = createBottomTabNavigator({
      Profile: {
        screen: Profile,
        navigationOptions: {
        tabBarIcon: ({ focused }) => (
          <Icon
            name='rowing' />
          )
          }
      },
      EventInfo: {
        screen: EventInfo,
        navigationOptions: {
        tabBarIcon: ({ focused }) => (
        <Icon
          name='rowing' />
          )
        }
    },
    }, {
      initialRouteName:'Profile',
    });
    
    ...
    

    如果这有帮助,请告诉我。

    【讨论】:

    • @Alex 酷。那么请务必接受它作为正确答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多