5

我正在使用react-native-vector-icons我的 React 本机项目。最近,当我打开我的应用程序时,它一直显示我在该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",

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

4

3 回答 3

1

I had the same problem. It's related to manually linking vs autolinking (new version)

Details on autolinking

Solution: npx react-native unlink react-native-vector-icons npm run android

npm run android actually runs: react-native run-android

于 2021-01-25T22:32:37.910 回答
1

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

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

于 2020-08-02T16:16:49.287 回答
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}
///>
于 2020-07-15T09:37:29.347 回答