由于expo 34.0.0更新字体不再加载,您知道我该如何解决? [英] since expo 34.0.0 update fonts doesn´t load anymore, do you know how can I fix it?

查看:95
本文介绍了由于expo 34.0.0更新字体不再加载,您知道我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有30个proyect,并且字体(fontello图标)现在可以成功加载3个月后,我重新打开proyect,直到更新expo,字体也没有加载,即使我创建了一个新的proyect,字体也没有 (我已经从 import { Font } from 'expo';import * as Font from 'expo-font';) 这是有问题的小吃 https://snack.expo.io/@emmalv/bold-香蕉

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

奇怪的是,在expo-cli中,当我运行相同的代码并打印加载状态时,首先返回false,然后返回true,然后中间显示红色屏幕,表示字体尚未通过Font.loadAsync加载

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

我尝试过的另一件事就像新文档说的那样,使用expoAssetId

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

但我遇到另一个错误

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

预期行为 图标加载并正确显示 实际行为 加载时引发异常'fontFamily"../assets/fonts/sowaicons"不是系统字体,并且尚未通过Font.loadAsync加载.并显示一个正方形而不是图标

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

环境

  • Windows 10
  • sdkVersion:35.0.0,
  • 博览会:^ 35.0.0,
  • 展览字体:〜7.0.0

推荐答案

我创建了工作示例: https://snack.expo.io/@djalik/custom-fonts

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

更改CustomIcon代码:

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

并将this.state.setState ...替换为this.setState

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

这篇关于由于expo 34.0.0更新字体不再加载,您知道我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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