You started a react native application and now it’s time to add custom fonts to your app, for example google fonts. Let’s see how we can achieve this in our react native application.
First step in our react native app is to add a small configuration in
file.package.json
In the above picture we take advantage of react native package manager and we added the the path for the
folder, the place where you should add all the custom fonts for the react native application.assets
After we added the configuration in
don’t forget to create package.json
folder in the root of the application.assets
All we need to do right now is to choose a custom font from google fonts, so head to the https://fonts.google.com/ and look for the right font, i choose Roboto for this example.
Next step is to add the font pressing on plus icon and then click on download top-right icon in order to get Roboto files locally.
Copy all the fonts downloaded locally to your
directory and then run assets/fonts
to link all the assets.react-native link
Adding Fonts to Android
If you check the
folder from the app and search for the fonts, you will see all the custom fonts copied to the android folder android
.android/app/src/main/assets/fonts/
React Native Styles
Now because we have all the fonts linked in react-native app it’s simple to add the font to react native styles.
const styles = StyleSheet.create({ demo: { fontFamily: "Roboto", fontSize: 20, textAlign: "center", color: "#333333", marginBottom: 5 } });
3 Comments
Does not work, it leads to a 500 error and the package,json stuff is deprecated.
Hi,
After you run “react-native link” in your app you should check also if the fonts are placed in the “android” folder
Roboto is the default font anyway on Android