React Native Elements 图标未显示在按钮上

Kit*_*Cat 1 reactjs react-native

你好,

我正在尝试在React-Native-Elements Button组件中使用图标。我没有收到错误或警告,但我最终得到了一个空按钮。

这是我的一些包含按钮的代码:

<Col size={20}>
    <Button icon={<Icon name="heart" color="#00aced"/>} size={30} buttonStyle={style.button}/>
</Col>
Run Code Online (Sandbox Code Playgroud)

我希望有人可以帮助我,因为我不知道为什么它没有出现。

提前致谢!

根据要求提供更多信息:

import { Button } from 'react-native-elements';
import Icon from 'react-native-vector-icons/FontAwesome';

const style = {
   button: {
        backgroundColor: '#6A5ACD',
        borderRadius: 10,
        justifyContent: 'center',
        alignItems: 'center',
        width: '100%',
        height: '100%'
      }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过其他的导入,比如 Fontawesome。

小智 10

尝试这个: -

<Col size={20}>
    <Button 
    icon={{name: 'envira', type: 'font-awesome'}} 
    size={30} buttonStyle={style.button}/>
</Col>
Run Code Online (Sandbox Code Playgroud)

如果仍然没有得到图标,那么你必须安装'react-native-vector-icons'

-- npm install react-native-vector-icons --save 
-- react-native link
Run Code Online (Sandbox Code Playgroud)

  • 已经尝试过,但我收到此警告(不是错误):“失败的道具类型:提供给“图标”的值“[object Object]”的道具“名称”无效,预期为以下之一:--分配图标名称” --` (2认同)