React Native Async字体加载

问题描述 投票:1回答:1

我正在使用 react-native-cli 构建一个 React 原生代码项目,有没有办法在没有 expo 的情况下 Async Load 字体?在我的cli原生项目中,简单地从'expo'导入{ Font }会有问题吗?

react-native expo
1个回答
1
投票

如果你想使用外部字体(如Google字体等)或任何矢量图标(如蚂蚁图标),你必须在应用程序渲染前加载,就像这样。

import * as Font from "expo-font";
import { AppLoading } from "expo";

async componentDidMount() {
    await Font.loadAsync(
      "antoutline",
      require("@ant-design/icons-react-native/fonts/antoutline.ttf")
    );
    await Font.loadAsync(
      "antfill",
      require("@ant-design/icons-react-native/fonts/antfill.ttf")
    );
    this.setState({ isReady: true });
}

render() {
    const { theme, currentTheme, isReady } = this.state;
    if (!isReady) {
      return <AppLoading />;
    }
    const Loader = createAppContainer;
    return (
      <Provider theme={theme}>
        <Loader  />
      </Provider>
    );
  }
© www.soinside.com 2019 - 2024. All rights reserved.