Skip to content

The simplest font loading for your react native app available

Notifications You must be signed in to change notification settings

unimonkiez/react-native-font-loader

Repository files navigation

react-native-font-loader

npm versionBuild Status

Import and use fonts easily in your react-native app

Usage

  • Install
    # file-loader is peerDependency
    npm install --save-dev react-native-font-loader file-loader
    # or yarn
    yarn add -D react-native-font-loader file-loader
  • Add loader to your webpack-config
    ...
     module: {
        rules: [
          {
              test: /\.ttf$/,
              use: [
                {
                  loader: 'react-native-font-loader',
                  options: {
                    path: './assets/',
                  },
                },
              ]
          }
        ]
     }
  • Import ttfs and use them in your code!
    import React, { Component } from 'react';
    import { View, Text, StyleSheet } from 'react-native';
    import someFontFamily from 'some.ttf';
    
    const stylesheet = StyleSheet.create({
      welcomeText: {
        fontFamily: someFontFamily,
        fontSize: 24,
      },
    });
    
    export default class App extends Component {
      render() {
        return (
          <View>
            <Text style={stylesheet.welcomeText}>
              Welcome to my React app!
            </Text>
          </View>
        );
      }
    }

About

The simplest font loading for your react native app available

Resources

Stars

Watchers

Forks

Packages

No packages published