Adding a default font when using StackNavigator in React Native
Asked Answered
P

1

0

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

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

Paradiddle answered 28/4, 2018 at 21:0 Comment(0)
B
0

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

Example

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
Briquet answered 28/4, 2018 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.