Use custom-font in React-Native

前端 未结 8 2109
孤独总比滥情好
孤独总比滥情好 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:41

    UPDATE

    You don't need to install rnpm manually now. After step one, in step two, you can just use the command react-native link and all your assets will be linked. rnpm is now being merged with react-naitve. Checkout this commit on RN https://github.com/facebook/react-native/commit/e8b508144fdcdea436cf4d80d99daec757505c70


    There is an easier way of doing things through `rnpm. It adds fonts to both android and ios. Place the font you want to add to a suitable location inside your project directory. In your package.json just add the following:

    step1

    ...
        "rnpm": {
              "assets": ["path/to/your/font/directory"]
        },
    ...
    

    step2

    Then from command line do: rnpm link

    you can now happily use your fonts in your app.

    Note: you have to have rnpm installed for this to work. Just do npm install -g rnpm

    Here is the documentation: https://github.com/rnpm/rnpm#advanced-usage

提交回复
热议问题