React 本机矢量图标不适用于当前版本 0.60

React native vector icon not working on current version 0.60

React 本机自动链接不适用于 React 本机矢量图标。我用这个将其固定为 android https://github.com/oblador/react-native-vector-icons/issues/1035

但是在 IOS 我仍然面临问题。如果有人解决了这个问题,请告诉我...谢谢!

这是我遇到的问题的截图。

如果您在 iOS 上执行了 react-native link,则执行 cd ios,然后执行 pod install

一些包仍然需要维护者更新才能与 React Native 一起使用。

无论如何,如果你不想 link 进入你的 podfile 并添加:

  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

之后做我之前说的相同步骤

这对我在升级项目和全新 RN 0.60.0 上有效

对于 IOS 将此添加到 ios/projectname/Info.plist

<key>UIAppFonts</key>
    <array>
        <string>AntDesign.ttf</string>
        <string>Entypo.ttf</string>
        <string>EvilIcons.ttf</string>
        <string>Feather.ttf</string>
        <string>FontAwesome.ttf</string>
        <string>FontAwesome5_Brands.ttf</string>
        <string>FontAwesome5_Regular.ttf</string>
        <string>FontAwesome5_Solid.ttf</string>
        <string>Foundation.ttf</string>
        <string>Ionicons.ttf</string>
        <string>MaterialCommunityIcons.ttf</string>
        <string>MaterialIcons.ttf</string>
        <string>Octicons.ttf</string>
        <string>SimpleLineIcons.ttf</string>
        <string>Zocial.ttf</string>
    </array>

对于 Android 将此行添加到 android/app/build。gradle

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

这解决了我的问题,并在两个平台上都对本机矢量图标做出反应。

字体、图像和其他外部资产仍应使用 react-native link 命令 linked,这是唯一的原因命令仍然存在。

但是,link 资产的配置发生了变化,过去曾经是通过在 package.json 中放置一个 rnpm 条目,其中包含要 link 的路径。检查 here.

现在拥有 fontawesome linked 的正确方法是拥有一个 react-native.config.js 文件。

1 - 创建一个 react-native.config.js 文件

 module.exports = {
      project: {
        ios: {},
        android: {},
      },
      assets: [
        './node_modules/react-native-vector-icons/PATH_TO_FONT_A',
        './node_modules/react-native-vector-icons/PATH_TO_FONT_B',
      ],
    };

2 - 运行 命令

react-native link

这一次,现在,link 命令将生成一条日志消息,例如

info Linking assets to ios project
warn Group 'Resources' does not exist in your Xcode project. We have created it automatically for you.
info Linking assets to android project
success Assets have been successfully linked to your project

运行

npx react-native link

在根文件夹项目中解决此问题。

希望对您有所帮助。

从 'react-native-vector-icons/Feather' 导入图标;

Icon.loadFont();

试试这个