React-Native 无法解析字体模块

React-Native can't resolve module for fonts

我正在开始一个非常基础的构建。 我正在为 pm 使用 `create-react-native-app' 和 yarn。

从那里我试图完成的就是加载 'native-base' 一些 UI 元素。

在 app.js 文件中,我唯一添加的是来自 native-base 的按钮组件。

<Button> <Text></Text> </Button>

并且包含了原生基础。

收到一些错误后 couldn't resolve module '@expo/vector-icons' 我去安装了@expo/vector-icons,然后就搞砸了 运行 react-native link.

现在可以找到@expo/vector-icons,但是找不到Ionicons.ttf开头的字体。

所以。从那里我将所有字体下载到 assets/fonts/ 目录,然后根据我在博览会网站上找到的一些文档将其包含在我的 app.js 文件中。

import { Font } from 'exponent';
///
export default class App extends React.Component {
  componentDidMount() {
    Font.loadAsync({
      'ionicons': require('./assets/fonts/Ionicons.ttf'),
    });
  }
///

我加载自定义字体的方式是将它们作为应用程序提供的字体列表添加到 Info.plist 文件中:

并且它们还需要在构建阶段的提供资源中:

之后就可以在react native中CSS中的fontFamily属性中使用了。确保在添加字体后再次清理并构建项目,以便将它们复制到设备。