【发布时间】:2018-04-03 00:33:06
【问题描述】:
我正在尝试在 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
但我得到这个错误:
可能是什么问题
【问题讨论】:
标签: reactjs react-native fonts react-router react-navigation