Javascript 该字体不是系统字体
我的应用程序已经有了第一个版本。我正在修一些东西。通过重新启动手机上的应用程序进行修改,会出现以下错误: fontFamily“FunctionLH”不是系统字体,尚未加载 通过Font.loadAsync 然而,我以前从未遇到过这个问题,字体加载正确没有问题。。。我很好地使用Font.loadAsync。我绝对不理解这种担心。。。 你能帮我吗 下面是app.js的代码,我在这里加载字体Javascript 该字体不是系统字体,javascript,react-native,fonts,Javascript,React Native,Fonts,我的应用程序已经有了第一个版本。我正在修一些东西。通过重新启动手机上的应用程序进行修改,会出现以下错误: fontFamily“FunctionLH”不是系统字体,尚未加载 通过Font.loadAsync 然而,我以前从未遇到过这个问题,字体加载正确没有问题。。。我很好地使用Font.loadAsync。我绝对不理解这种担心。。。 你能帮我吗 下面是app.js的代码,我在这里加载字体 export default class App extends React.Component { c
export default class App extends React.Component {
constructor(props) {
super(props);
Text.defaultProps = Text.defaultProps || {};
Text.defaultProps.allowFontScaling = false;
this.state = {
isFirstConnection: true,
status: 0,
fontLoaded: false
};
}
async UNSAFE_componentWillMount() {
let lang = await retrieveAppLang();
let isConnected = await userSessionActive();
if (lang.length == 2) {
i18n.changeLanguage(lang);
}
if (isConnected === true && this.props && this.props.navigation) {
this.props.navigation.navigate("TabBar");
}
}
performTimeConsumingTask = async () => {
return new Promise((resolve) =>
setTimeout(() => {
resolve("result");
}, 750)
);
};
async componentDidMount() {
await Font.loadAsync({
FunctionLH: require("./assets/fonts/FunctionLH-Light.ttf")
});
const data = await this.performTimeConsumingTask();
if (data !== null) {
this.setState({
isFirstConnection: false,
status: 1,
fontLoaded: true,
});
}
}
render() {
if (this.state.status == 1) {
if (this.state.isFirstConnection && this.state.fontLoaded) {
return <SplashScreen />;
} else {
return <Navigation screenProps={'Authentication'} />;
}
}
return (
<ImageBackground
source={require("./assets/images/background.jpg")}
style={{ flex: 1 }}
>
<View style={[styles2.container, styles2.containerCentered]}>
<StatusBar hidden={true} />
<View style={styles2.subContainer}>
<Image
style={styles2.logo}
source={require("./assets/images/logo.png")}
/>
<ActivityIndicator size="large" color="#43300E" />
<Text>{i18n.t("app.loading") + "..."}</Text>
</View>
</View>
</ImageBackground>
);
}
}
导出默认类App扩展React.Component{
建造师(道具){
超级(道具);
Text.defaultProps=Text.defaultProps | |{};
Text.defaultProps.allowFontScaling=false;
此.state={
是的,
状态:0,
错误:错误
};
}
异步不安全组件willmount(){
let lang=等待检索applang();
let isConnected=wait userSessionActive();
if(lang.length==2){
i18n.改变语言(lang);
}
if(isConnected==true&&this.props&&this.props.navigation){
this.props.navigation.navigate(“TabBar”);
}
}
performTimeConsumingTask=async()=>{
返回新承诺((解决)=>
设置超时(()=>{
决议(“结果”);
}, 750)
);
};
异步组件didmount(){
等待Font.loadAsync({
FunctionLH:要求(“./assets/font/FunctionLH Light.ttf”)
});
const data=等待此操作。performTimeConsumingTask();
如果(数据!==null){
这是我的国家({
isFirstConnection:false,
现状:1,
是的,
});
}
}
render(){
if(this.state.status==1){
if(this.state.isFirstConnection&&this.state.fontload){
返回;
}否则{
返回;
}
}
返回(
您应该尝试运行react native link,将自定义文件链接到iOS和android资源(res>font)您好,谢谢您的回答。我只是像那样运行命令?我正要尝试一下。您会看到类似这样的内容:info Linking assets to ios project info Linking assets to android project success assets已成功链接到您的项目(节点:10544)警告:在循环依赖项内访问模块导出的不存在属性“PadLevel”(使用节点--跟踪警告…
显示警告的创建位置),它给出:“成功资产已成功链接到您的项目”,但再次运行应用程序时,我仍然存在问题。下面是您需要做的事情。(1)在根react-native项目中创建一个文件,将其命名为react-native.config.js,并添加以下代码module.exports={project:{ios:{},android:{},//分组为“project”},assets:[“/assets/font/”],//保持不变};……打开您的package.json文件并将其添加到列表中:“rnpm”:{“资产”:[“/”/assets/font/“]}然后尝试使用本机链接