在React Native中使用StackNavigator时添加默认字体 [英] Adding a default font when using StackNavigator in React Native

查看:112
本文介绍了在React Native中使用StackNavigator时添加默认字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过遵循robertmylne在

I am trying to set a default font by following the code by robertmylne on this page. However, it tells me to place the code in my constructor in my App.js. The problem is that I am using a StackNavigator and as far as I know I cannot use a constructor. My code looks something like this:

import Module1 from './components/Module1'
import Module2 from './components/Module2'
import Module3 from './components/Module3'

const App = StackNavigator(
    {
        Module1: { screen: Module1 },
        Module2: { screen: Module2 },
        Module3: { screen: Module3 }
    },
    { headerMode: 'none'}
)

export default App

使用StackNavigator时是否可以通过某种方式使相关代码正常工作?

Is there some way to get the relevant code working when using a StackNavigator?

推荐答案

StackNavigator

StackNavigator is a HOC which returns a component. You can use it as any other component.

示例

import Module1 from './components/Module1'
import Module2 from './components/Module2'
import Module3 from './components/Module3'

const Navigator = StackNavigator(
    {
        Module1: { screen: Module1 },
        Module2: { screen: Module2 },
        Module3: { screen: Module3 }
    },
    { headerMode: 'none'}
)

class App extends Component {
  constructor(props) {
    super(props)
    // any other code you need to add
  }

  render() {
    return <Navigator />
  }
}

export default App

这篇关于在React Native中使用StackNavigator时添加默认字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆