1

I have used Font.loadAsync many times but for some reason, I keep getting errors while trying to use it this time. (code is at the pastebin, it got formatted weirdly on here)

pastebin

import React from "react";
Noehy
  • 23
  • 6
  • Where are you calling Font.loadAsync in the code? I don't see it in what you posted. It helps to paste it here too, so your post doesn't depend on an external resource that might go away at some point. – Abe Jun 23 '22 at 03:28
  • Does [this](https://stackoverflow.com/a/69275330/13170636) help. – Kartikey Jun 23 '22 at 12:29

2 Answers2

1

I was also struggling with Font.loadAsync in my latest project. I decided to use the expo-font module instead. You can initialize this module in App.js and it will load the fonts for all of your screens.

Here is an example:

import React from "react";
...

import { useFonts } from "expo-font"; //need to load fonts asynchronously

...

const App = () => {

  const [loaded] = useFonts({// function for expo-font 
    RobotoBlack: FONTS.Roboto-Black.ttf,
    RobotoBold: FONTS.Roboto-Bold.ttf,
    RobotoRegular:FONTS.RobotoRegular.ttf,
  });
  if (!loaded) {
    return null;
  }

...
server_unknown
  • 407
  • 2
  • 17
0

Try implementing require before your fonts. May need to hunt down where your fonts are coming from in your directory.


const App = () => {

  const [loaded] = useFonts({// function for expo-font 
    RobotoBlack: require(*font source directory*),
    RobotoBold: require(*font source directory*),
    RobotoRegular: require(*font source directory*)
  });
  if (!loaded) {
    return null;
  }

Source: https://docs.expo.dev/versions/latest/sdk/font/

Evan Scallan
  • 148
  • 1
  • 5