question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Font not passing to components

See original GitHub issue

I have tried following the docs and a bunch of posts, but I cannot get my fonts to format any react-native-paper components. I follow the expo example of how to load fonts using loadFontAsync(), and when I pass these fonts to my own components using the style prop fontFamily: 'Rubik-Regular' the font works so I know it is not an issue of the font not existing.

I am using expo 39.0.3, react-native 0.63.3, react-native-paper 4.2.0, and react-native-vector-icons 7.1.0.

Any ideas on how to go about making this font work would be greatly appreciated.

import React from 'react';
import { Provider as ReduxProvider } from 'react-redux'
import configureStore from './store'
import { configureFonts, DefaultTheme, Provider as PaperProvider } from 'react-native-paper'
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import AppNavigator from './components/AppNavigator'

const store = configureStore();

const fontConfig = {
    default: {
        regular: {
            fontFamily: 'Rubik-Regular',
            fontWeight: 'normal',
        },
        medium: {
            fontFamily: 'Rubik-Black',
            fontWeight: 'normal',
        },
        light: {
            fontFamily: 'Rubik-Light',
            fontWeight: 'normal',
        },
        thin: {
            fontFamily: 'Rubik-LightItalic',
            fontWeight: 'normal',
        },
    },
};

const myTheme = {
    dark: false,
    roundness: 30,
    fonts: configureFonts(fontConfig),
    colors: {
        ...DefaultTheme.colors,
        primary: '#0d80d6',
        accent: '#E68FAE',
        background: '#C6E1F2',
    },
    animation: {
        scale: 1.0,
    },
}

export default class App extends React.Component {
    render() {
        return (
            <ReduxProvider store={store}>
                <PaperProvider theme={myTheme}>
                    <AppNavigator />
                </PaperProvider>
            </ReduxProvider>
        );
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Trancevercommented, Dec 15, 2020

As an intermediate solution, we are happy to merge a PR to our documentation that explains how this function work. Would be awesome if you could submit such a PR 🙏

1reaction
RichardLindhoutcommented, Dec 15, 2020

This is my config.

import { Platform } from 'react-native';

const fonts = Platform.select<any>({
  web: {
    regular: {
      fontFamily: 'Montserrat',
      fontWeight: '500',
    },
    medium: {
      fontFamily: 'Montserrat',
      fontWeight: '600',
    },
    light: {
      fontFamily: 'Montserrat',
      fontWeight: '400',
    },
    thin: {
      fontFamily: 'Montserrat',
      fontWeight: '400',
    },
  },
  ios: {
    regular: {
      fontFamily: 'Montserrat',
      fontWeight: '500',
    },
    medium: {
      fontFamily: 'Montserrat',
      fontWeight: '600',
    },
    light: {
      fontFamily: 'Montserrat',
      fontWeight: '400',
    },
    thin: {
      fontFamily: 'Montserrat',
      fontWeight: '100',
    },
  },
  default: {
    regular: {
      fontFamily: 'Montserrat-Medium',
      fontWeight: 'normal',
    },
    medium: {
      fontFamily: 'Montserrat-SemiBold',
      fontWeight: 'normal',
    },
    light: {
      fontFamily: 'Montserrat-Regular',
      fontWeight: 'normal',
    },
    thin: {
      fontFamily: 'Montserrat-Thin',
      fontWeight: 'normal',
    },
  },
});

export default fonts;

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Native-Paper Theme won't use Custom Fonts
I am working on a RN app using react-native-paper to handle theming and UI. I have the theme working to format my components,...
Read more >
How to Build a Title Component and Import Multiple Fonts
Welcome back to the course. In this video, we are going to style our application here, so let's look at our design real...
Read more >
API Reference - styled-components
A function that receives the props that are passed into the component and computes a value, that is then going to be merged...
Read more >
Text Style Props - React Native
Specifies font weight. The values 'normal' and 'bold' are supported for most fonts. Not all fonts have a variant for each of the...
Read more >
Font-face and Styled Components - clairecodes
You may already have them, or you can use a tool like google-webfonts-helper to download the font files for Google web fonts. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found