失败的道具类型:提供给"FontAwesomeIcon"的道具"样式"无效



我的代码在App.js

import * as React from 'react'
import { View } from 'react-native'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faEllipsisV } from '@fortawesome/free-solid-svg-icons'
library.add(faEllipsisV)
export default function App() {
return (
<View>
<FontAwesomeIcon icon="ellipsis-v" style={styles.moreOptions} />
</View>
)
}
const styles = StyleSheet.create({
moreOptions: {
fontSize: 5,
color: primary,
},
})

生成以下警告:

警告:失败的道

具类型:提供的道具style无效FontAwesomeIcon. in FontAwesomeIcon (at App.js:44( in App (at withExpoRoot.web.js:10( in ExpoRootComponent (at registerRootComponent.web.js:6( 在根组件中 在div 中(由视图创建( 在视图中(由应用容器创建( 在div 中(由视图创建( 在视图中(由应用容器创建( 在应用容器中

但是在字体真棒文档中有一种样式。如何解决这个问题?

顺便说一句,color工作虽然有警告,但fontSize不起作用。

我认为FontAwesomeIcon本身不是RNText组件,因此fontSize不是一个可接受的道具。

请改用<FontAwesomeIcon ... size={5}>

根据文档和 samuli 所说@kodfire,FontAwesome 确实支持样式表,但它只接受颜色作为其中的参数,没有别的。如果要更改大小,请使用size而不是传递fontSize

查看文档图标文档

import React, { Component } from 'react'
import { View, StyleSheet } from 'react-native'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { faCoffee } from '@fortawesome/free-solid-svg-icons'

type Props = {}
const style = StyleSheet.create({
icon: {
color: 'blue'
}
})
export default class App extends Component<Props> {
render() {
return (
<View>
<FontAwesomeIcon icon={ faCoffee } style={ style.icon } size={32}/>
</View>
)
}
}

如有任何问题,请还原。

相关内容

最新更新