DEV Community

Cover image for Use Custom Fonts In ReactNative App
Ashirbad Panigrahi
Ashirbad Panigrahi

Posted on

6 3

Use Custom Fonts In ReactNative App

Let's use custom fonts in you react-native app


Create a react native app with typescript or javascript

npx react-native init [ProjectName] --template react-native-template-typescript
Enter fullscreen mode Exit fullscreen mode

Create a fonts folder & copy your fonts into this folder

mkdir fonts
Enter fullscreen mode Exit fullscreen mode

Create react-native.config.js file in the root of your project

touch react-native.config.js
Enter fullscreen mode Exit fullscreen mode

Add following code in react-native.config.js file

module.exports = {
  assets: ['./fonts/'],
};
Enter fullscreen mode Exit fullscreen mode

Run following command to link fonts to your project

npx react-native-asset
Enter fullscreen mode Exit fullscreen mode

Now open App.tsx file and use your custom font family

import {SafeAreaView, StyleSheet, Text} from 'react-native';
import React from 'react';

const App = () => {
  return (
    <SafeAreaView style={styles.container}>
      <Text style={styles.Italic}>Italic</Text>
      <Text style={styles.Bold}>Bold</Text>
      <Text style={styles.Regular}>Regular</Text>
      <Text style={styles.Light}>Light</Text>
    </SafeAreaView>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {padding: 10},  
  Bold: {fontSize: 30, fontFamily: 'Nunito-Bold'},
  Light: {fontSize: 30, fontFamily: 'Nunito-Light'},
  Regular: {fontSize: 30, fontFamily: 'Nunito-Regular'},
  Italic: {fontSize: 30, fontFamily: 'Nunito-Italic'},
});
Enter fullscreen mode Exit fullscreen mode

Get Full Source Code In GitHub

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay