Font family Roboto light and bold in react native

user3521011 picture user3521011 · May 4, 2017 · Viewed 30.3k times · Source

I',m making some changes on the text in my react native application: I need to specify Roboto light for paragraphs and Roboto Bold for titles. I need to have the same look of the text in both iOS and android apps: so i need to make it work for both I tried this code line of code

text : { fontFamily: 'sans-serif-light' },

but i get this error: enter image description here

I tried this type from the official documentation and it's working fine

title : { fontFamily: 'Cochin' },

--> So i think the problem is in the Roboto fontfamily itself .. Any help?

Answer

Roman Akash picture Roman Akash · May 4, 2017

To add custom fonts to your app store all your ttf files in a directory. Add the following code to your package.json file.

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

Then run react-native link To use the font use the same name on the ttf file in fontFamily.