【问题标题】:react-native-vector-icon show "wrong" iconreact-native-vector-icon 显示“错误”图标
【发布时间】:2020-07-15 09:28:49
【问题描述】:

我在我的 React 本机项目中使用 react-native-vector-icons。最近,当我打开我的应用程序时,它一直显示我在name 字段中填写的错误图标,或者显示该图标不存在(“问号”)。

我觉得很尴尬,因为大约一两周后就正常了。我一直在 SOF 或他们的 github 上搜索,但感觉没有希望。

你能帮我解决这个问题吗?

<Icon
    containerStyle={{
        display: (this.state.email.length > 0) ? 'flex' : 'none',
        marginRight: normalize(10),
    }}
    name="mail-outline"
    type="ionicon"
    color="#7384B4"
    size={22}
    onPress={() => {
        this.setState({ email: '' });
    }}
/>

这是我的代码,它应该显示邮件图标,但我有这个

这是我在package.json中使用的一些相关依赖版本

"react": "16.9.0",
"react-native": "0.61.3",
"react-native-elements": "^1.2.0",
"react-native-vector-icons": "^7.0.0",

谢谢,祝你有美好的一天。

【问题讨论】:

    标签: reactjs react-native react-native-vector-icons


    【解决方案1】:

    您应该以特定方式声明import Icon

    示例:import Icon from 'react-native-vector-icons/Ionicons'

    例如:

    import Icon from 'react-native-vector-icons/Ionicons'
    //or you can use
    //import Ionicons from 'react-native-vector-icons/Ionicons'
    
    //usage
    
    <Icon
        //containerStyle={{
            //display: (this.state.email.length > 0) ? 'flex' : 'none',
            //marginRight: normalize(10),
        //}}
        //i think it should be `style` not `containerStyle`
        //except you are using another lib to show icon
        style={{
            display: (this.state.email.length > 0) ? 'flex' : 'none',
            marginRight: normalize(10),
        }}
        name="mail-outline"
        color="#7384B4"
        size={22}
        onPress={() => {
            this.setState({ email: '' });
        }}
    />
    
    //another way
    //<Ionicons
    //{...all props you need to define}
    ///>
    

    【讨论】:

      【解决方案2】:

      这可能是由过时的图标字体文件引起的,您可能已经更新了软件包版本而不是字体文件。尝试从“字体”文件夹中重新复制字体文件。

      https://github.com/oblador/react-native-vector-icons/tree/master/Fonts

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题。它与手动链接与自动链接(新版本)有关

        Details on autolinking

        解决方案: npx react-native unlink react-native-vector-icons npm run android

        npm run android 实际运行:react-native run-android

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多