-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding custom fonts in react native 60+ #25852
Comments
Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety? 👉 Click here if you want to take another look at the Bug Report issue template. |
For future visitors: run |
I've follow these steps, but after running |
|
I'm using React Native 0.60.5 and ran Probably should add that while this worked with Android right away, I had to go into XCode and build/run the app from there before my custom font could work in ios. |
Hey @sudomann, the difference is that you installed |
why the font name is named another name ? how to query? |
@shenl923 I'm not sure I understand what you are asking. Explain better? |
@shenl923 are you referring to the fact that Android uses the font's filename whereas iOS uses the font's PostScript name? In case yes, this article here describes this issue, maybe it helps. |
react-native link doesn't work for v. 0.60 |
@jallynme
|
Seems like this here is a duplicate of #25697? |
Facing this issue on Android! Using:
|
where do I have to create the file react-native.config.js? |
When you create a react native project, you give it a name, and a folder is created with that name. That is the root. In that project root folder, there should be at least 2 folders, For example I start a new react native project with |
And, if you have more than one font and you have one folder for each font you have to add one by one something like this
|
@MiguelGrability You shouldn't have to list out each font, for our project we are doing: module.exports = {
project: {
ios: {},
android: {}
},
assets: ['./assets/fonts/']
} |
@saadq If you add new font files to |
I haven't tried adding new fonts after my initial setup, but I believe you would need to run |
Doesn't work for me on react-native 0.60.5, adding this to package.json however did
|
@BaterdeneA @react-native-bot
I added react-native.config.js
Even i run "react-native link" command after check all things but nothing works yet. |
If you're using expo, you might want to check this guide. |
"react-native": "0.60.5" Font for android dont work |
same :( |
Same here :(
|
Same here :( "react": "16.9.0", on android npx react-native link runs fine and the generated app-debug.apk does contain the ttf files under assets\fonts |
finally get it working |
@jmlavoier I have the same issue. did you find a solution? |
I had the same issue despite the clear instructions. For some reason, it didn't work over iOS, so I tried to add a reference link directly in Xcode in: "Build Phases" -> "Copy Bundle Resources" -> "+" -> "#select your font from assets/fonts folder" I also added it in my iOS Info.plist:
and it worked. |
Life saver !!! |
If you don't see any changes after taking the above steps, try exiting the app and run |
@Michaelvons Hey, I'm trying your way but it does not work for iOS,
|
root folder name should be react-native.config.js |
Since you are on ios, the right command would be |
https://medium.com/@mehrankhandev/ultimate-guide-to-use-custom-fonts-in-react-native-77fcdf859cf4 worked on iOS and Android with RN 0.62.2. If it's not working for you: Double-check
Good luck! |
if you have multiple targets on iOS (e.g a staging build) react-native link will only add the fonts to the main target, you can update the others in build-phases -> copy bundle resources and then update your info.plist to include these fonts as well. |
It still doesn't work for me on android "react-native": "0.62.2".
This is what I tried:
|
Is, there a way to link fonts only? |
I have followed this tutorial and it's working fine for android and ios both. The naming of the font should exactly the same as it's named in styles WITHOUT using any fontWeight.
I got one issue in ios(Unrecognized font-family) and the issue was font name I am using in style is different from actual font name(PostScript Name - That can be get by open it with any font editor and then view details). I have used birdfont.
|
I've stopped the iOS version, I'm just following with Android for a while. Whether I find the solution I will try again. |
Solution for iOS : Solution for Android : Error on iOS Good Luck |
Removing default style property like fontWeight also solves the problem because custom font has its own styling properties and will not work if you have added default react-native styling property like fontWeight. |
@shiroze That's way work for Android, |
Did you |
use |
OS: I Resolved by:
And my style After: |
same issue. tried everything. same issue |
@habeebtheprogrammer you try to stop all the app and run again? work for me |
npx react-native link worked for me, but be careful, file name should be react-native.config.js not react-native-config.js I've written complete step by step guide for linking fonts for both iOS and android. |
Thanks sirajalam049 your solution worked for me. |
still i have face same issue on 0.64.0 Solutionplease copy paste your font file to
if you have not find the folder of asset inside main folder. please create it assets/fonts folder Then do its working now without adding any config |
After react native 60 adding custom fonts have changed. Follow this short tutorial to simply add custom fonts in your app.
React Native CLI can be configured by creating a react-native.config.js at the root of the project. Depending on the type of a package, the set of valid properties is different. To add custom fonts we only need to add one line of code: assets: [‘./assets/fonts/’]
Then add your fonts in ./assets/fonts/ directory
And use like this: fontFamily: ‘Roboto-Regular’
Just that simple we have custom fonts in our react native app :)
If you like the article, don’t forget to clap and share it :)
Via Sergo Kupreishvili
The text was updated successfully, but these errors were encountered: