How to set default font family in React Native?

后端 未结 10 1013
鱼传尺愫
鱼传尺愫 2020-11-29 00:25

Is there an equivalent to this CSS in React Native, so that the app uses the same font everywhere ?

body {
  font-family: \'Open Sans\';
}

10条回答
  •  半阙折子戏
    2020-11-29 01:19

    For React Native 0.56.0+ check if defaultProps is defined first:

    Text.defaultProps = Text.defaultProps || {}
    

    Then add:

    Text.defaultProps.style =  { fontFamily: 'some_font' }
    

    Add the above in the constructor of the App.js file (or any root component you have).

    In order to override the style you can create a style object and spread it then add your additional style (e.g { ...baseStyle, fontSize: 16 })

提交回复
热议问题