Custom fontFamily for Text not working in either iOS or Android
See original GitHub issueIs 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
- Place contents of Nunito font fro Google (*ttf files) into project root’s
assets/fonts/
directory (here are the contents of that directory) - Add the following to my
package.json
:
"rnpm": {
"assets": [
"./assets/fonts/"
]
},
- Run
react-native link
- Verify that both Xcode/Info.plist and Android Studio reflects the new Nunito font:
- Run
./gradlew clean
fromandroid
directory, fresh install ofnode_modules
from scratch, fresh install of pods fromandroid
directory, restart both Xcode and Android Studio, reset npm cache, uninstall and reinstall app on variety of emulators and devices - Try setting
Text.defaultProps.style = {fontFamily: 'Nunito'};
in root component (App.js
) - Try setting
{fontFamily: 'Nunito'}
style for a singleText
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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you try to match
font filename
andfontFamily
name.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