gpt4 book ai didi

reactjs - Font.loadAsync() 无法解析自定义字体的模块(React Native 和 Expo)

转载 作者:行者123 更新时间:2023-12-03 13:35:33 28 4
gpt4 key购买 nike

我的应用程序使用 CRNA 和 Expo,我的问题是 Font.loadAsync() 异步函数无法在我的项目目录的 asset/fonts/文件夹中找到 .otf 字体文件。我绝对确定目录和文件名是正确的。我收到此错误。

link to image of my error screen

这是我的代码:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Font, AppLoading } from 'expo'
import Root from './js/Root';

export default class App extends Component {

constructor(props) {
super(props)
this.state = {
fontLoaded: false
}
}

async componentDidMount() {
await Font.loadAsync({
"Light": require('./assets/fonts/SemplicitaPro-Light.otf')
})
this.setState({ fontLoaded: true })
}

render() {
if (!this.state.fontLoaded) {
return <AppLoading />
}
return <Root />;
}
}

这是我的 package.json:

    {
"name": "Zumer",
"version": "0.1.0",
"private": true,
"devDependencies": {
"flow-bin": "^0.40.0",
"jest-expo": "^0.4.0",
"react-native-scripts": "0.0.28",
"react-test-renderer": "16.0.0-alpha.6"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch",
"flow": "flow"
},
"packagerOpts": {
"assetExts": ["ttf", "otf"]
},
"jest": {
"preset": "jest-expo",
"tranformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
]
},
"dependencies": {
"@expo/vector-icons": "^4.0.0",
"expo": "^16.0.0",
"native-base": "^2.1.2",
"react": "16.0.0-alpha.6",
"react-native": "^0.43.4",
"react-native-elements": "^0.11.1",
"react-navigation": "^1.0.0-beta.8",
"react-redux": "^5.0.4",
"redux": "^3.6.0",
"redux-observable": "^0.14.1",
"redux-persist": "^4.6.0",
"rxjs": "^5.3.0"
}
}

Expo 是否不支持 .otf 文件格式?

最佳答案

我通过将 otf 文件转换为 ttf 解决了此问题

关于reactjs - Font.loadAsync() 无法解析自定义字体的模块(React Native 和 Expo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43695617/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com