How to use Custom Fonts in React Native?
Published On: 02/07/2022 | Category:
React Native
Hi Guys,
Now, let's see tutorial of how to use custom fonts in react native. if you want to see example of how to add custom fonts in react native then you are a right place. you can understand a concept of how to implement custom fonts in react native. This tutorial will give you simple example of react native custom fonts example. follow bellow step for how to create custom fonts in react native.
Let's start following example:
Step 1: Download ProjectIn the first step run the following command to create a project.
expo init ExampleAppStep 2: Install and Setup
In this step, you can install expo-font:
expo install expo-fontStep 3: App.js
In this step, You will open the App.js file and put the code.
import React, { useState, useEffect } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import * as Font from 'expo-font'; const App = () => { const [fontsLoaded, setFontsLoaded] = useState(false); const loadFonts = async () => { await Font.loadAsync({ Gantari: require('./assets/fonts/Gantari-VariableFont_wght.ttf'), 'Lobster-Regular': { uri: require('./assets/fonts/Lobster-Regular.ttf'), display: Font.FontDisplay.FALLBACK, }, }); setFontsLoaded(true); } useEffect(() => { loadFonts(); }, []); return ( <View style={styles.container}> {fontsLoaded ? ( <View style={styles.container}> <Text style={{ fontSize: 30 }}>Default Font</Text> <Text style={{ fontFamily: 'Lobster-Regular', fontSize: 30 }}>Lobster-Regular</Text> <Text style={{ fontFamily: 'Gantari', fontSize: 30 }}>Gantari</Text> </View> ): null } </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, }); export default App;Run Project
In the last step run your project using the below command.
expo start
You can QR code scan in Expo Go Application on mobile.
Output :
It will help you...