react-native-失败的prop类型:提供给`FontAwesomeIcon`的无效prop`style`

问题描述 投票:0回答:2

我在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。 在FontAwesomeIcon中(在App.js:44) 在App中(withwithExpoRoot.web.js:10) 在ExpoRootComponent中(在registerRootComponent.web.js:6处) 在RootComponent中 在div中(由View创建) 在视图中(由AppContainer创建) 在div中(由View创建) 在视图中(由AppContainer创建) 在AppContainer中

但是font awesome documentation中有一种样式。如何解决?

顺便说一句,尽管color工作正常,但有警告,但fontSize不工作。

reactjs react-native font-awesome
2个回答
1
投票

我认为FontAwesomeIcon本身不是RN Text组件,因此fontSize不是可接受的属性。

改为使用<FontAwesomeIcon ... size={5}>


0
投票

@@ kodfire,根据文档和samuli所说,FontAwesome确实支持样式表,但它仅接受颜色作为其参数,除此之外别无其他。如果要更改大小,请使用size,而不要传递fontSize

检查文档icon docs

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>
    )
  }
}

如有任何疑问,请回复。

© www.soinside.com 2019 - 2024. All rights reserved.