React Native Unrecognized font family not fixing

前端 未结 2 1630
再見小時候
再見小時候 2021-01-12 17:11

The fonts are in my asset folder, they are also inside xcode copy bundle resources, and also inside resource folder. I already also ran react-native link, but it still doesn

相关标签:
2条回答
  • 2021-01-12 17:58

    React Native Part:

    Add fonts to assets/fonts of the root folder of react-native project

    react-native-project/
      package.json
      ios/
      android/
      assets/
        fonts/
          GROBOLD...
          ...
    

    Add the below snippet to package.json

    "rnpm": {
      "assets": [
        "./assets/fonts/"
      ]
    }  
    

    Run the following command in your react-native project to link your assets.

    react-native link react-native-vector-icons 
    

    iOS Part:

    Check info.plist for the font files whether they have added already.

    Delete derived data, build and run your Xcode project.

    Double check the fonts added to project by navigating to the AppDelegate.m file and add these lines of code below NSURL *jsCodeLocation;

    for (NSString* family in [UIFont familyNames])
    {
      NSLog(@"%@", family);
      for (NSString* name in [UIFont fontNamesForFamilyName: family])
      {
        NSLog(@" %@", name);
      }
    }
    

    Android Part:

    Copy the font files to if they are not exist already.

    android/
        app/
          src/
            main/
              assets/
                fonts/
                  GROBOLD...
    

    0 讨论(0)
  • 2021-01-12 18:10

    Please update below with your code:

    "rnpm": {
        "assets": [
          "./src/assets/fonts/"
        ]
      }
    

    You missed "/" that's why your compiler didn't find the font file.

    Let me know if you still got any issues.

    0 讨论(0)
提交回复
热议问题