[英]react-native-vector-icons/Feather Icon always “?”
Good Morning, I'm trying to use library https://github.com/oblador/react-native-vector-icons#installation早上好,我正在尝试使用库https://github.com/oblador/react-native-vector-icons#installation
import Icon from 'react-native-vector-icons/Feather';
After I installed it and followed every step of installation在我安装它并遵循安装的每一步之后
I tried to run it with expo with this code:我尝试使用以下代码使用 expo 运行它:
function BottomTabNavigator1() {
return (
<Tabs.Navigator
tabBarOptions={
{
activeTintColor: "#2F7C6E",
inactiveTintColor: "#222222"
}
}
apperance={
{
whenInactiveShow : "both"
}
}
>
<Tabs.Screen name="HomeScreen" component={HomeScreen}
options={
{
tabBarIcon: ({ focused, color, size }) => (
<Icon
name="Home"
size={size ? size : 12}
color={focused ? color : "#222222"}
focused={focused}
color={color}
/>
)
}
}
/>
<Tabs.Screen name="DefaultScreen" component={DefaultScreen}
options={
{
tabBarIcon: ({ focused, color, size }) => (
<Icon
name="Rocket"
size={size ? size : 12}
color={focused ? color : "#222222"}
focused={focused}
color={color}
/>
)
}
}
/>
</Tabs.Navigator>
)
}
No error messages appeared, but the and 'Home" won't show off, only shown on expo view as image '?'没有出现错误消息,但“主页”不会显示,仅在 expo 视图上显示为图像“?” Am I missing something? help please
我错过了什么吗?请帮助
I think react-native-vector-icons doesn't support Expo as that package needs native modules to be linked which isn't supported in an Expo project unless you eject.我认为react-native-vector-icons不支持 Expo 因为 package 需要链接本机模块,这在 Expo 项目中不受支持,除非您弹出。
You can use @expo/vector-icons as an alternative instead.您可以使用@expo/vector-icons作为替代。
According to its docs:根据其文档:
This library is a compatibility layer around @oblador/react-native-vector-icons to work with the Expo asset system.
该库是围绕@oblador/react-native-vector-icons 的兼容层,可与 Expo 资产系统一起使用。
In your case you can do the following:在您的情况下,您可以执行以下操作:
Replace:代替:
import Icon from 'react-native-vector-icons/Feather';
<Icon
name="Home"
size={size ? size : 12}
color={focused ? color : "#222222"}
focused={focused}
color={color}
/>
With:和:
import { Feather } from '@expo/vector-icons';
<Feather
name="home"
size={size ? size : 12}
color={focused ? color : "#222222"}
focused={focused}
color={color}
/>
You may need to run:您可能需要运行:
npm i @expo/vector-icons
Here is a snack to see the result: https://snack.expo.io/@dcangulo/2e6e4e这是一个看结果的零食: https://snack.expo.io/@dcangulo/2e6e4e
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.