Use custom-font in React-Native

前端 未结 8 2049
孤独总比滥情好
孤独总比滥情好 2020-12-04 10:36

I would like to use custom font in my app, but I keep getting error

[RCTLog][tid:0x78f70450][RCTConvert.m:581]>Unrecognized font family \'Roboto\'
         


        
8条回答
  •  無奈伤痛
    2020-12-04 10:53

    1. add the font files (i.e. .otf OR .ttf) in root/assets/font folder in your project.

    2. in package.json: rnpm: "assets": ["./assets/font"],

      1. if after building your fonts are not being supported then add this one file in root level:

    react-native.config.js

     module.exports = {
        project: {
            ios: {},
            android: {},
        },
        assets: ['./assets/fonts']
        };
    
    1. ex: font-name -> Robotto-Regular.ttf then use it like below in styles:
    fontFamily: 'Robotto-Regular'
    
    1. run react-native link
    2. Then in android side(android studio) and ios side(Xcode) sync the project.
    3. run react-native run-android OR react-native run-ios

    This should resolve any errors which will be coming of fonts not supporting and you can use your custom fonts.

提交回复
热议问题