React Native Custom Fonts Example

Jul 02, 2022 . Admin

Hi Guys,

This article will provide some of the most important example react native custom fonts example. This article will give you simple example of how to add custom fonts in react native. you'll learn how to implement custom fonts in react native. This tutorial will give you simple example of how to use custom fonts in react native. So, let's follow few step to create example of how to create custom fonts in react native.

Let's start following example:

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: Install and Setup

In this step, you can install expo-font:

expo install expo-font
Step 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...

#React Native