简体   繁体   English

React 图标与 React 本机导航不兼容

[英]React icons Incompatible with react native navigation

I want to use this icon from React icons= HiOutlineMenuAlt1 as my drawer icon in react native navigation.我想使用 React icons= HiOutlineMenuAlt1 中的这个图标作为本机导航中的抽屉图标。 However i try to use as shown below it brings an error(see below) Note: This error happens with all icons when used in the navigation但是我尝试如下所示使用它会带来错误(见下文)注意:在导航中使用时,所有图标都会出现此错误

Minimal sample repository最小样本库

import { HiOutlineMenuAlt1} from "react-icons/hi";
<Drawer.Navigator
  screenOptions={({ navigation }) => ({
      headerLeft: () => <HiOutlineMenuAlt1 size={24} color="white" />,
  })
      ....
</Drawer.Navigator>

ERROR SHOWN显示错误

Invariant Violation: View config getter callback for component path must be a function (received undefined).不变违规:查看组件路径的配置 getter 回调必须是 function(收到未定义)。 Make sure to start component names with a capital letter.确保组件名称以大写字母开头。

Expected behavior预期行为

it should display an icon and no error should be shown它应该显示一个图标并且不应该显示任何错误

This library is incompatible with React Native.该库与 React Native 不兼容。 Try to use this for example https://github.com/oblador/react-native-vector-icons尝试使用它,例如https://github.com/oblador/react-native-vector-icons

May want to try this:可能想试试这个:

<Drawer.Navigator
  screenOptions={({ navigation }) => ({
      headerLeft: <HiOutlineMenuAlt1 size={24} color="white" />,
  })
      ....
</Drawer.Navigator>

But I agree with the other answer, you typically don't want to grab fonts from the web for mobile application.但我同意其他答案,您通常不想从 web 中获取 fonts 用于移动应用程序。 You want the fonts to come installed with the app, so you store it locally on the device.您希望 fonts 与应用程序一起安装,因此您将其存储在设备本地。

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

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