我正在使用react-native-cli构建一个React本机代码项目,是否有没有Expo的Async Load字体?仅在我的cli本地项目中从“ expo”导入{Font}会出现问题吗?
答案 0 :(得分:1)
如果您想使用外部字体(例如Google字体等)或任何矢量图标(例如ant图标),则必须在应用渲染之前加载,就像这样
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>
);
}