由于 expo 34.0.0 更新字体不再加载,你知道我该如何解决吗? [英] since expo 34.0.0 update fonts doesn´t load anymore, do you know how can I fix it?
问题描述
我有 expo 30 proyect,字体(fontello 图标)现在加载成功 3 个月后我在更新 expo 之前重新打开了 proyect,即使我创建了一个新的 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
更改 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屋!