繁体   English   中英

不从 react-native-vector-icons/FontAwesome 加载图标

[英]Not loading Icons from react-native-vector-icons/FontAwesome

你们今天对 react-native-vector-icons/FontAwesome 有问题吗? 我使用的是 react-native 版本 >0.6 所以我认为问题不在于链接。

正如你们在图片中看到的那样,它没有显示我要求的任何图标,我不知道发生了什么......

这是我的 android 模拟器上显示的图片: Print-Scream-Icon-Not-Showing-up

import React from 'react'
import {View, Text, StyleSheet, TouchableOpacity} from 'react-native'
import Icon from 'react-native-vector-icons/FontAwesome'



export default function ActionButton(props) {

    return(
        <TouchableOpacity>
        <View style={styles.container}>
           
           <Icon name='plus' size={30} color='#777' />
           <Icon name='trash' size={30} color='#777' />
           <Icon name='search'  size={30} color='#777' />
        </View>
        </TouchableOpacity>
    )
}

const styles = StyleSheet.create({
    container:{
        justifyContent:'center',
        alignItems:'center',
        width:80,
        height:40,
        backgroundColor:'#FFF',
        elevation:9,
        marginTop:20,
        borderRadius:6,
        paddingVertical:15,
        marginBottom:10
       
    }
})


所以库react-native-vector-icons不支持 react-native > 6.0 上的自动链接,这意味着您必须运行命令npx react-native link react-native-vector-icons来链接,在重新链接后运行 android 仿真器,一切正常。 .. 特别感谢帮助我回答的匿名者!!!

如果你使用的是 expo,你可以这样写:

import { FontAwesome } from "@expo/vector-icons";

<FontAwesome name="dollar" size={60} color={"green"} />

您可以尝试像这样添加 loadFont function 吗?

import React from 'react'
import {View, Text, StyleSheet, TouchableOpacity} from 'react-native'
import Icon from 'react-native-vector-icons/FontAwesome'

Icon.loadFont(); // <- Add this line


export default function ActionButton(props) {

    return(
        <TouchableOpacity>
        <View style={styles.container}>
           
           <Icon name='plus' size={30} color='#777' />
           <Icon name='trash' size={30} color='#777' />
           <Icon name='search'  size={30} color='#777' />
        </View>
        </TouchableOpacity>
    )
}

const styles = StyleSheet.create({
    container:{
        justifyContent:'center',
        alignItems:'center',
        width:80,
        height:40,
        backgroundColor:'#FFF',
        elevation:9,
        marginTop:20,
        borderRadius:6,
        paddingVertical:15,
        marginBottom:10
       
    }
})

暂无
暂无

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

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