How to load “ionicons” font in expo sdk33?

倖福魔咒の 提交于 2019-12-10 17:06:21

问题


after upgrading to expo sdk 33.0.0, when i build my react native expo app everything is ok but as soon as the app starts the the following error shows up:

fontFamily "ionicons" is not a system font and has not been loaded through Font.loadAsync

before the update i was using the sdk version 32.0.0 and everything was ok.

I tried to add the font as explained here https://docs.expo.io/versions/latest/guides/using-custom-fonts/ in my app.js componentDidMount function:

const Ionicons = require("./fonts/Ionicons.ttf");
...
componentDidMount() {
    ...
    Font.loadAsync({
        "Avenir-Book": AvenirBook,
        "Avenir-Light": AvenirLight,
        "Ionicons": Ionicons,
    })
}
...

I also try to change the name in the loadAsync from "Ionicons" to "ionicons" but nothing changed.

The "Ionicons.ttf" inside the fonts folder file was copied from the node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts folder

---------EDIT--------- In all my react native expo project src i have not a single reference to Ionicon

Any help is appreciated, Thanks


回答1:


To import Ionicons icons do

import { Ionicons } from '@expo/vector-icons';
// use like
<Ionicons name="md-checkmark-circle" size={32} color="green" />

And to import custom fonts, add the path to the font to require.

import { Font } from 'expo';

componentDidMount() {
  Font.loadAsync({
    'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'),
  });
}


来源:https://stackoverflow.com/questions/56750684/how-to-load-ionicons-font-in-expo-sdk33

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!