Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom fonts not working on React-Native 0.62

Tags:

react-native

I'm trying to use a custom font on my app but it doesn't work. I have followed numerous steps from other similar questions but nothing works.

I'm not getting any error.

The path to the assets folder: Assets source

This is what I tried:

    • Creating react-native.config.js file on root project with the following code:
module.exports = {
    project: {
      ios: {},
      android: {},
    },
    assets: ['./src/assets/fonts']
  };
    • Running react-native link: This didnt give me any errors:
info Linking assets to ios project
info Linking assets to android project
success Assets have been successfully linked to your project
    • Naming the font exactly as its named in styles WITHOUT using any fontWeight:
<Text style={[styles.texto_Titulo, {fontFamily: "LatoBlack"}]}>
      ENTRADA
</Text>
    • Recompiling with npx react-native run-android after react-native link

Why is this not working?

like image 211
Aldimir Avatar asked Mar 30 '20 07:03

Aldimir


3 Answers

Okay so this happens to be a current bug for React Native 0.62. The workaround for this problem is copying the assets/fonts folder to /android/app/src/main/ path. This fixed the problem.

like image 111
Aldimir Avatar answered Sep 20 '22 18:09

Aldimir


My solution was to remove fontWeight from my text styles. Seems font family does not work if fontWeight is provided

like image 43
Sardorek Aminjonov Avatar answered Sep 22 '22 18:09

Sardorek Aminjonov


https://github.com/facebook/react-native/issues/25852#issuecomment-826526064

still i have face same issue on 0.64.0

Solution

please copy paste your font file to

android/app/src/main/assets/fonts

if you have not find the folder of asset inside main folder. please create it assets/fonts folder

Then do react-native link

its working now without adding any config

like image 30
prasanth Avatar answered Sep 20 '22 18:09

prasanth