since expo 34.0.0 update fonts doesn´t load anymore, do you know how can I fix it?

回眸只為那壹抹淺笑 提交于 2019-12-11 04:17:10

问题


I have expo 30 proyect and the fonts ( fontello icons ) load succesful now 3 months later I reopen the proyect before update expo and fonts does´t load even if I create a new proyect the fonts does´t (I have already changed the import from import { Font } from 'expo'; to import * as Font from 'expo-font';) here's a snack with the problem https://snack.expo.io/@emmalv/bold-banana

it's curious that in expo-cli when I run the same code and print the state of loading first return false and before true and inmediately show red screen saying that font has not been loaded through Font.loadAsync

I've tried wirtting everything in the app class instead of loading the fonts from another file and the behavior is the same

other thing I've tried is like the new documentation says, use expoAssetId

const expoAssetId = require("assets/fonts/custom-icon-font.ttf");
const Icon = createIconSetFromFontello(fontelloConfig, 'FontName', expoAssetId);

but I get another error

C.replace is not a function. (In 'C.replace(/\.(otf|ttf)$/,'')', 'C.replace' is undefined)

Expected Behavior the icons load and show correctly Actual behavior when load throw an exception 'fontFamily "../assets/fonts/sowaicons" is not a system font and has not been loaded through Font.loadAsync.' and show a square instead of the icon

Enviroment

  • Windows 10
  • sdkVersion: 35.0.0,
  • expo: ^35.0.0",
  • expo-font: ~7.0.0

回答1:


I created working example: https://snack.expo.io/@djalik/custom-fonts

change CustomIcon code:

import { createIconSetFromFontello } from '@expo/vector-icons';
import fontelloConfig from '../assets/fonts/config.json';
// const ttf = require("../assets/fonts/sowaicons.ttf");
// import myfont from "../assets/fonts/sowaicons.ttf";
const Icon = createIconSetFromFontello(fontelloConfig, 'sowaicons'); 

and replace this.state.setState... to this.setState



来源:https://stackoverflow.com/questions/58368279/since-expo-34-0-0-update-fonts-doesn%c2%b4t-load-anymore-do-you-know-how-can-i-fix-i

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