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.

Can't use loaded fonts as per documentation

See original GitHub issue

Following the Using Custom Fonts guide to load a custom font and then using fontFamily: 'my-font-name' in a StyleSheet always results in the following error message:

fontFamily ‘my-font-name’ is not a system font and has not been loaded through Exponent.Font.loadAsync.

However, if I use fontFamily: Font.style('my-font-name').fontFamily it works correctly. I’m not sure if this means the documentation is incorrect (maybe a breaking change was introduced recently?) or if this is some sort of bug.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ryanvanderpolcommented, Jul 13, 2017

One thing that might help is in old versions of the documentation there should be a big warning banner at the top that says something about this version being outdated. Might cause people to look twice at the documentation version

1reaction
AlexandreRobacommented, Apr 22, 2018

Hi All,

I’m having the same problem. Lost tow hours on this. Here is my code. Any idea?

import React,{Component} from 'react';
import {  Text, View } from 'react-native';

import { Font } from 'expo';


export default class App extends Component{
    state = {
        ready: false,
    };

    componentDidMount(){
        this._loadAssetsAsync();
    }

    async _loadAssetsAsync(){
        try {
            await Font.loadAsync({
                'Roboto-Regular':require('./assets/fonts/Roboto-Regular.ttf')
            });
        }
        catch(e) {
            Log.error(e);
        }
        finally{
            console.log('Roboto is loaded:' + Font.isLoaded('Roboto-Regular'));
            this.setState({ready: true});
        }
    }

    render(){
        return (

                <View style={{flex:1,marginTop:100}}>

                    this.state.ready ? (
                    <Text style={{fontFamily:'Roboto-Regular'}}>New Font in Robotto</Text>
                    ) : null
                </View>
        )
    }
}

And My package.json

{
  "name": "test app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-native-scripts": "1.13.2",
    "jest-expo": "26.0.0",
    "react-test-renderer": "16.3.0-alpha.1"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "apollo-cache-inmemory": "^1.1.12",
    "apollo-client": "^2.2.8",
    "apollo-link-http": "^1.5.4",
    "expo": "^26.0.0",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.1",
    "react": "16.3.0",
    "react-apollo": "^2.1.3",
    "react-native": "~0.54.1"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Best Font Loading Strategies and How to Execute Them
Zach Leatherman wrote up a comprehensive list of font loading strategies that have been widely shared in the web development field.
Read more >
Best practices for fonts - web.dev
Be cautious when using preload to load fonts #​​ Inlining font declarations and adjusting stylesheets may be a more effective approach. These ...
Read more >
Solved: Reader doesn't recognize installed font - 9896699
Please navigate to Adobe Reader's Preferences from Edit>Preferences>Page Display>Select "Use Local Fonts">Click OK>Close the PDF and Adobe Reader.
Read more >
How to use web fonts in CSS - LogRocket Blog
Designers recommend using fonts sparingly, with just one or two typefaces per document; Custom fonts typically require a few hundred KB.
Read more >
how do I add new fonts to Adobe Acrobat Pro DC??
If you're trying to repair a document from someone else, that uses a given font and you can't find it via DC for...
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