反应本机异步字体加载 [英] React Native Async Font Loading

查看:53
本文介绍了反应本机异步字体加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用react-native-cli构建一个React本机代码项目,是否有没有Expo的Async Load字体?仅在我的cli本地项目中从"expo"导入{Font}会出现问题吗?

I'm building a React native code project using react-native-cli, is there anyway to Async Load fonts without Expo? Would there be a problem simply importing { Font } from 'expo' in my cli native project?

推荐答案

如果要使用外部字体(例如Google字体等)或任何矢量图标(例如ant图标),则必须在应用渲染之前加载,像这样

If you want to use the external font (e.g. Google fonts, etc.) or any vector icons (e.g. ant icons), you have to load before app render, like this

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

这篇关于反应本机异步字体加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆