【问题标题】:React Native Async Font LoadingReact Native 异步字体加载
【发布时间】:2019-01-08 15:22:29
【问题描述】:

我正在使用 react-native-cli 构建一个 React 本机代码项目,是否可以在没有 Expo 的情况下异步加载字体?在我的 cli 原生项目中从“expo”导入 { Font } 会不会有问题?

【问题讨论】:

  • 您在不使用 Expo 的情况下设法解决了吗?
  • 很遗憾没有。

标签: react-native expo


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 2019-12-30
    相关资源
    最近更新 更多