Custom font React-Native, [Unhandled promise rejection: ReferenceError: Can't find variable: ExpoFontLoader]
Custom font React-Native, [Unhandled promise rejection: ReferenceError: Can't find variable: ExpoFontLoader]
我正在尝试在我的 react-native 应用程序中实现自定义字体。我按照 expo 的文档进行操作,但收到一条错误消息:
[Unhandled promise rejection: ReferenceError: Can't find variable: ExpoFontLoader]
node_modules/expo-font/build/Font.js:103:25 in _loadSingleFontAsync$
node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
... 14 more stack frames from framework internals
这是我来自 Login.js
的代码
import React, {useState} from 'react'
import { StyleSheet, Text, View, Button, TextInput } from 'react-native'
//import firebase and it's auth module
import firebase from 'firebase/app';
import 'firebase/auth';
import * as Font from 'expo-font';
export default class Login extends React.Component {
constructor(){
super()
this.state={
fontLoaded:false
}
}
async componentDidMount() {
await Font.loadAsync({
'play': require('../assets/fonts/PressStart2P-Regular.ttf'),
});
this.setState({ fontLoaded: true });
}
render() {
return (
<View style={styles.container}>
{this.state.fontLoaded ? (
<Text style={styles.title}>Login</Text>
) : null
}
我从未使用过变量:ExpoFontLoader
,而且我找不到关于此错误的其他信息。带有字体的文本登录没有显示,我找不到办法...有人可以帮助我吗?
检查您的 .ttf
文件路径。
我发现了与此错误类似的内容:
https://github.com/expo/expo/issues/4626#issuecomment-503138343
我自己修复了它,由于某种原因,当我安装 expo 时它使用了 expo-font 的 7.0.0 版本。这必须是 8.0.0 版,所以我安装了正确的版本,现在可以使用了!
我正在尝试在我的 react-native 应用程序中实现自定义字体。我按照 expo 的文档进行操作,但收到一条错误消息:
[Unhandled promise rejection: ReferenceError: Can't find variable: ExpoFontLoader]
node_modules/expo-font/build/Font.js:103:25 in _loadSingleFontAsync$
node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
... 14 more stack frames from framework internals
这是我来自 Login.js
import React, {useState} from 'react'
import { StyleSheet, Text, View, Button, TextInput } from 'react-native'
//import firebase and it's auth module
import firebase from 'firebase/app';
import 'firebase/auth';
import * as Font from 'expo-font';
export default class Login extends React.Component {
constructor(){
super()
this.state={
fontLoaded:false
}
}
async componentDidMount() {
await Font.loadAsync({
'play': require('../assets/fonts/PressStart2P-Regular.ttf'),
});
this.setState({ fontLoaded: true });
}
render() {
return (
<View style={styles.container}>
{this.state.fontLoaded ? (
<Text style={styles.title}>Login</Text>
) : null
}
我从未使用过变量:ExpoFontLoader
,而且我找不到关于此错误的其他信息。带有字体的文本登录没有显示,我找不到办法...有人可以帮助我吗?
检查您的 .ttf
文件路径。
我发现了与此错误类似的内容: https://github.com/expo/expo/issues/4626#issuecomment-503138343
我自己修复了它,由于某种原因,当我安装 expo 时它使用了 expo-font 的 7.0.0 版本。这必须是 8.0.0 版,所以我安装了正确的版本,现在可以使用了!