图标导航器上没有显示React Native的图标

问题描述 投票:0回答:1

我有问题使用createBottomTabNavigator显示图标。我正在使用react-native-ionicons,如果我在代码中放置任何类型的Icon,但它没有显示在标签栏上,它可以正常工作。我已经设置了showIcon: true

这是我正在尝试的代码:

import React from 'react';
import {View, Text} from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';

import HomeScreen from './screens/HomepageScreen';

  class SettingsScreen extends React.Component {

    render() {
      return (
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <Text>Settings!</Text>
        </View>
      );
    }
  }

const BottomNavigation = createBottomTabNavigator(
    {
      Home: HomeScreen,
      Settings: SettingsScreen,
    },
    {
      tabBarOptions: {
        inactiveTintColor: 'gray',
        swipeEnabled: true,
        showLabel: true,
        showIcon: true
      },
    }
  );

export default createAppContainer(BottomNavigation);

在哪里HomepageScreen.js:

import React from 'react';
import {View, Text, Image, ScrollView} from 'react-native';
import {Card, CardItem, Right, Left} from 'native-base';
import {Header} from 'react-native-elements';
import Icon from 'react-native-ionicons'

class HomeScreen extends React.Component {

    state = {
        news: []
    }

    static navigationOptions = {
        title: 'Noticias',
        tabBarIcon: ({tintColor}) => {
            <Icon style={{width: 10, height: 10, color: 'black'}} ios="ios-add" android="md-add" />
        }
    }

    render() {
      return (
        //code
      );
    }
}

export default HomeScreen;

我错过了什么吗?

react-native react-navigation
1个回答
0
投票

大小可能太小了,如果你打算使用color={tintColor}你需要放tintColor

import React from 'react';
import {View, Text, Image, ScrollView} from 'react-native';
import {Card, CardItem, Right, Left} from 'native-base';
import {Header} from 'react-native-elements';
import Icon from 'react-native-ionicons'

class HomeScreen extends React.Component {
   static navigationOptions = {
        title: 'Noticias',
        tabBarIcon: ({tintColor}) => {
            <Icon color={tintColor} ios="ios-add" android="md-add" />
        }
    }


    render() {
      return (
        //code
      );
    }
}

export default HomeScreen;

希望能帮助到你!

© www.soinside.com 2019 - 2024. All rights reserved.