question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom fontFamily for Text not working in either iOS or Android

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra 10.13.2 Node: 9.4.0 Yarn: 1.3.2 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.52.0 => 0.52.0

Steps to Reproduce

  1. Place contents of Nunito font fro Google (*ttf files) into project root’s assets/fonts/ directory (here are the contents of that directory)
  2. Add the following to my package.json:
"rnpm": {
    "assets": [
	"./assets/fonts/"
    ]
},
  1. Run react-native link
  2. Verify that both Xcode/Info.plist and Android Studio reflects the new Nunito font: screen shot 2018-01-17 at 10 41 59 am screen shot 2018-01-17 at 10 44 44 am
  3. Run ./gradlew clean from android directory, fresh install of node_modules from scratch, fresh install of pods from android directory, restart both Xcode and Android Studio, reset npm cache, uninstall and reinstall app on variety of emulators and devices
  4. Try setting Text.defaultProps.style = {fontFamily: 'Nunito'}; in root component (App.js)
  5. Try setting {fontFamily: 'Nunito'} style for a single Text component

Expected Behavior

I expected globally setting Text.defaultProps.style = {fontFamily: 'Nunito'}; to result in the font being applied everywhere in my app, or at the very least setting {fontFamily: 'Nunito'} style for a single Text component to work.

Actual Behavior

In all cases, I still only observe my app using the default RN font family.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lwinkyawmyatcommented, Jan 18, 2018

Can you try to match font filename and fontFamily name.

{ 
  fontFamily: 'Nunito-Reqular' // if filename is Nunito-Reqular.ttf
}
{ 
  fontFamily: 'Nunito-Bold' // if filename is Nunito-Bold.ttf
}
1reaction
hamadasamir85commented, May 1, 2018

I found out that font names on ios are different from the file name. the files name might be ‘GE_SS_TWO_MEDIUM.ttf’ but if you check the font info with fontbook app you will find the name is ‘GE SS TWO’. using the file name as fontfamily works on android but does not work on ios ,and vise versa so my solution was to use Platform check on style

fontFamily: Platform.OS === 'ios' ? 'GE SS TWO':'GE_SS_TWO_MEDIUM'

worked for me so far

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom font not working in React Native
In case somebody is reading this because their setup is fine and custom fonts work on iOS and in some cases don't work...
Read more >
iOS 14.x Custom Font Issue
We have noticed an issue on 14.x related to loading the fonts mentioned in our CSS. The font file is not getting loaded...
Read more >
Common Mistakes With Adding Custom Fonts to Your iOS ...
Common Mistakes With Adding Custom Fonts to Your iOS App · 1. Include your fonts in your XCode project · 2. Make sure...
Read more >
Custom Fonts Not Displaying On Front End
This can happen because different browsers render fonts differently, so to prevent any inconsistencies, it is important to add all font variations to...
Read more >
Add a font as an XML resource
Use your fonts, either a single font file or a font from a font family, in TextView objects or in styles by using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found