在React Navigation DrwaerNavigator中未显示的图标

时间:2019-02-28 19:36:28

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

我正在尝试将图标添加到以下简单的React Navigation DrawerNavigator

  export default createAppContainer(createDrawerNavigator({
  Home: {
    screen: HomeScreen,
    icon: 'home'
  },
  Screen1: {
    screen: Screen1
  },
  Screen2: {
    screen: Screen2
  },
  Screen3: {
    screen: Screen3
  },
}));

抽屉显示得很好,但图标却没有。

2 个答案:

答案 0 :(得分:0)

图标必须是<Image><View>之类的组件,而不是字符串。

答案 1 :(得分:0)

确保您已导入反应本机矢量图标以在“任何组件”中使用图标。

 import Ionicons from 'react-native-vector-icons/Ionicons';
    export default createAppContainer(createDrawerNavigator({
    Home: {
    screen: HomeScreen,
    navigationOptions: {
      drawerIcon: () => <Ionicons name="ios-home" size={30} style={{ width: 24 }} 
    color="#000" />
    }
    },
    Screen1: {
    screen: Screen1
    },
    Screen2: {
    screen: Screen2
    },
      Screen3: {
    screen: Screen3
      },
    }));