我正在尝试在RN Expo项目中设置默认字体(Lato-Regular)。我使用setCustomText来实现这一目标。https://github.com/Ajackster/react-native-global-props。这种方法在非Expo项目中运行得很好,但是现在我将我的项目移植到Expo中,似乎在应用程序的默认字体方面存在问题。
但我收到了这个错误提示:
可能出现了什么问题?
import React, { Component } from 'react'
import { Styles } from 'react-native'
import { Root } from './src/config/router'
import {
setCustomText
} from 'react-native-global-props'
import { Font } from 'expo'
class App extends Component {
constructor() {
super()
this.state = {
currentTab: null,
fontLoaded: false
}
}
getCurrentRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index]
if (route.routes) {
return this.getCurrentRouteName(route)
}
return route.routeName;
}
componentDidMount() {
Font.loadAsync({
'Lato-Regular': require('./src/assets/fonts/Lato-Regular.ttf')
});
this.setState({
fontLoaded: true
},
() => this.defaultFonts());
}
defaultFonts(){
const customTextProps = {
style: {
fontFamily: 'Lato-Regular'
}
}
setCustomText(customTextProps)
}
render() {
console.log( this);
return (
this.state.fontLoaded ?
<Root
screenProps={{currentScreen: this.state.currentTab}}
/> : null
)
}
}
export default App
但我收到了这个错误提示:
![enter image description here](https://istack.dev59.com/mzOXY.webp)
react-native-global-props
,我也学到了 :) - Freez