Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFonts hook randomly failing to load fonts #21885

Closed
crschmidt2 opened this issue Mar 28, 2023 · 73 comments
Closed

useFonts hook randomly failing to load fonts #21885

crschmidt2 opened this issue Mar 28, 2023 · 73 comments

Comments

@crschmidt2
Copy link

crschmidt2 commented Mar 28, 2023

Summary

When I use the {useFonts, Abel_400Regular} hook from "@expo-google-fonts/abel" and {HankenGrotesk_300} from "@expo-google-fonts/hanken-grotesk" the Abe font will fail to load on my iOS Expo Go app and my Android studio emulator. However, when I add the function

const onLayoutRootView = useCallback(async () => {
		if (fontsLoaded) {
		  await SplashScreen.hideAsync();
		}
	  }, [fontsLoaded]);

and save my editor the font loads fine. But when I reload each app from Expo Cli the font refuses to load again unless I remove the function, save in my editor, add the function, and save again. I had this issue earlier with locally saved .otf font files, so I believe the issue is with the { useFonts } hook. I've tried all fixes I can find online and nothing's helped.

EDIT: I found out it's loading the fonts whenever I hot-reload after changing any code in the render return statement for a function component. I just added an if (fontsLoaded) {} and saved and it loaded the fonts. I'm guessing it's throwing the Font not loaded error slightly before the font gets a chance to load, but when I use a splashscreen to wait for it to load it gets stuck on the splashscreen forever.

What platform(s) does this occur on?

Android, iOS

SDK Version

~48.0.9

Environment

expo-env-info 1.0.5 environment info:
    System:
      OS: Windows 10 10.0.19044
    Binaries:
      Node: 18.13.0 - C:\Program Files\nodejs\node.EXE
      npm: 9.6.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: AI-221.6008.13.2211.9619390
    npmPackages:
      @expo/webpack-config: ^18.0.1 => 18.0.2
      expo: ~48.0.9 => 48.0.9
      react: 18.2.0 => 18.2.0
      react-dom: 18.2.0 => 18.2.0
      react-native: 0.71.4 => 0.71.4
      react-native-web: ~0.18.10 => 0.18.12
    Expo Workflow: managed

Minimal reproducible example

Here is the minimum code I was able to reproduce the error with. When I change the return statement and hot-save the project, the render update fixes the font.

import React, { useCallback } from "react";
import {StyleSheet, Text} from 'react-native'
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { useFonts, Abel_400Regular } from "@expo-google-fonts/abel";
import { HankenGrotesk_300Light } from "@expo-google-fonts/hanken-grotesk";
import * as SplashScreen from "expo-splash-screen";

import HomeScreen from "./screens/HomeScreen";
import ActiveSubscriptionsScreen from "./screens/ActiveSubscriptionsScreen";
import CustomNavigationBar from "./components/CustomNavigationBar";
import LogInScreen from "./screens/LoginScreen";
import ViewOrdersScreen from "./screens/ViewOrdersScreen";
import CartScreen from "./screens/CartScreen";
import AccountScreen from "./screens/AccountScreen";
import SignUpScreen from "./screens/SignUpScreen";



export default function App() {
	const [fontsLoaded] = useFonts({
		Abel_400Regular,
		HankenGrotesk_300Light
	})

	const onLayoutRootView = useCallback(async () => {
		if (fontsLoaded) {
		  await SplashScreen.hideAsync();
		}
	  }, [fontsLoaded]);

	return (
		<Text style={{fontFamily: "Abel_400Regular", alignSelf: "center", marginTop: 500}}>Styling! :D Hooray!</Text>
	);
}

Here is one of the screens the font is running on

@crschmidt2 crschmidt2 added CLI Versioned Expo CLI -- `npx expo start` needs validation Issue needs to be validated labels Mar 28, 2023
@expo-bot expo-bot removed the needs validation Issue needs to be validated label Mar 28, 2023
@robert-nash
Copy link

I am also facing a similar issue

@crschmidt2
Copy link
Author

Robert: I actually figured out a fix that worked for me. For some reason the splashScreen would never register the value of fontsLoaded changing, but I was able to fix the issue by using the deprecated element called AppLoading from expo-app-loading. All I did was do
if (!fontsLoaded) { return <AppLoading/> }
This correctly kept the screen loading until the fonts were loaded. After they were loaded it stopped showing the loading screen. Hope this helps you out, and if anybody figures out why it's not working with SplashScreen please let me know

@EvanBacon EvanBacon removed the CLI Versioned Expo CLI -- `npx expo start` label May 17, 2023
@douglowder douglowder self-assigned this Aug 2, 2023
@expo-bot
Copy link
Collaborator

expo-bot commented Aug 2, 2023

Thank you for filing this issue!
This comment acknowledges we believe this may be a bug and there’s enough information to investigate it.
However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.

@douglowder
Copy link
Contributor

I took a look at this and I can reproduce this reliably on Android when downloading an EAS update and reloading the app with the update. Investigating.

@douglowder
Copy link
Contributor

ENG-9592

@douglowder
Copy link
Contributor

@crschmidt2 you are correct that you should show a loading component and not null while fonts are not loaded. Also, we recommend that you handle errors from the useFonts() API to prevent the splash screen from showing forever:

export default function App() {
	const [fontsLoaded, fontError] = useFonts({
		Abel_400Regular,
		HankenGrotesk_300Light
	})

	const onLayoutRootView = useCallback(async () => {
		if (fontsLoaded || fontError) {
		  await SplashScreen.hideAsync();
		}
	  }, [fontsLoaded, fontError]);

        if (!fontsLoaded && !fontError) { return <AppLoading/> }

	return (
		<Text style={{fontFamily: "Abel_400Regular", alignSelf: "center", marginTop: 500}}>Styling! :D Hooray!</Text>
	);
}

douglowder added a commit that referenced this issue Aug 9, 2023
Our examples of `useFonts()` usage do not include error handling.
Because of this, a customer can have trouble debugging the problem if
there is an error in loading fonts -- in our examples, the splash screen
will never hide. (See #21885 for such
an issue.)

I've updated the examples to show correct error handling.

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [x] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [x] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
@mphill
Copy link

mphill commented Sep 16, 2023

useFont will randomly return false for loaded. It appears to be completely random. There must be some loading timing or thread issue

Seeing this in Expo 49 currently, if you implemented useFont per the documentation:

  const onLayoutRootView = useCallback(async () => {
    if (fontsLoaded) {
      await SplashScreen.hideAsync();
    }
  }, [fontsLoaded]);

  if (!fontsLoaded) {
    return null;
  } 

Your app will randomly hang on the splash screen on iOS. I haven't confirmed on Android. It's easy to reproduce this. Force quit 10-15 times and you will get the app to hang on the splashscreen.

I also added a setTimeout to force the splash to hide because this is a pretty bad issue to have out in the wild. It possible a fresh install will never get into the app, I've seen this a few times now.

@carbonatedcoder
Copy link

@douglowder, in your example, you recommend proceeding into the app even if there is a fontError. If the font truly did not load and there was a fontError, is entering the app truly the recommended course of action? Won't that cause a flood of errors that look like fontFamily "[font_name]" is not a system font and has not been loaded through Font.loadAsync. in any component that uses the custom font (which are presumably many)?

We are also seeing the same behavior described by @mphill in Expo SDK 49. We are using the useFonts hook from within @expo-google-fonts/montserrat version 0.2.3. It seems to be completely random, but is reproducible if you try to force close and restart the app enough times. Since fontsLoaded is returning false, the app component never mounts and its onLayout callback never called, which is what should be hiding the splash screen.

@douglowder
Copy link
Contributor

You make a good point -- depending on the app, it may be desirable to show an error screen or have code that handles falling back to system fonts.

My main concern was that the splash screen be hidden even if errors occur, otherwise font problems will be very difficult to debug.

@mphill
Copy link

mphill commented Sep 24, 2023

For what it’s worth I don’t think this is the fonts hook that is failing, it's an assets loading issue. When this issue shows up, the in-app images don't load either.

@carbonatedcoder
Copy link

For what it’s worth I don’t think this is the fonts hook that is failing, it's a assets loading issue. When this issue shows up, the in-app images don't load either.

This does seem to be correct or at least related. In the errors we are seeing reported, it is complaining that the font asset file doesn't even exist.

File 'file:///var/mobile/Containers/Data/Application/[....]/Library/Application%20Support/.expo-internal/assets/node_modules/@expo-google-fonts/montserrat/Montserrat_400Regular.ttf' for font 'Montserrat_400Regular' doesn...

Given the version that is being logged, it looks like the issue is also causing the app to fallback to the bundle that was shipped with the binary build versus the latest OTA. This seems to be a pretty prevalent issue for us, so any additional findings would be welcome.

@carbonatedcoder
Copy link

@mphill have you found any usable workaround in the meantime? We are seeing the issue roughly every 10-15 app starts, which is pretty rough. Given that the underlaying issue appears to be something with the loading of assets (i.e. the font file doesn't even appear available to the app), we can't necessarily hide the splash screen (i.e. setTimeout method) and allow the user to proceed into the app if the font isn't there.

The issue appears to be temporarily fixed by a force quit + reopen of the app. But, it can return again randomly at any point.

Given that, we were going to programmatically restart the app with Updates.reloadAsync for the user upon failure, but that doesn't even seem to work either as it raises a separate exception, despite being successfully used elsewhere in the project and having updates enabled: Calling the 'reload' function has failed Caused by: Cannot call module method when expo-updates is disabled

@douglowder
Copy link
Contributor

@carbonatedcoder if you are seeing the message above, it means that you are not actually using expo-updates, and should remove it from your app.

@carbonatedcoder
Copy link

if you are seeing the message above, it means that you are not actually using expo-updates, and should remove it from your app.

@douglowder, thanks for the followup, but we do actually make use of expo-updates in the app and have a custom handler for OTA update checking/processing (checkForUpdateAsync, fetchUpdateAsync, and reloadAsync).

Additionally, we use reloadAsync in a few places throughout the app successfully to restart the app for different purposes. The only time it fails with this error is while being called during/after this assets issue is taking place. So, I'm not sure if it's something to do with the app falling back to the built in bundle or what.

@karamjb
Copy link

karamjb commented Sep 25, 2023

Hello,
I am using expo update
and I got font load error and the app not loaded

File 'file:///var/mobile/Containers/Data/Application/*****uuid/Library/Application%20Support/.expo-internal/assets/assets/fonts/Somar-Bold.otf' for font 'Somar-Bold' doesn't exist

@douglowder
Copy link
Contributor

@carbonatedcoder if you are going to use expo-updates, it needs to be configured to use EAS update server, or your own server that follows our updates protocol.

Could you share the contents of ios/<appname>/Supporting/Expo.plist?

@carbonatedcoder
Copy link

carbonatedcoder commented Sep 25, 2023

@douglowder, this is a managed workflow project so it's all default configuration when it comes to EAS. No custom servers are specified and we've used this for months without issue after switching from classic updates to EAS. We've never had issues with it.

The OTA updates are checked and download just fine, so the issue is not really with that process. The only reason I called out the updates exception is because our idea to "mask" this assets/font issue was to reload the app for the user but this exception is only seen when trying to call reloadAsync while this issue with the assets (font issue) is occurring. That error is not thrown anywhere else in our updates flow, which makes use of reloadAsync, elsewhere it just works.

The custom Updates strategy we use is similar to the one described here, with the addition of redirecting the user to a different screen while the update is happening. The updates.checkAutomatically key is set to ON_ERROR_RECOVERY so that the custom strategy is used.

@douglowder
Copy link
Contributor

Ok so this

Calling the 'reload' function has failed Caused by: Cannot call module method when expo-updates is disabled

is only happening at startup, when you detect the font loading issue?

@carbonatedcoder
Copy link

Ok so this

Calling the 'reload' function has failed Caused by: Cannot call module method when expo-updates is disabled

is only happening at startup, when you detect the font loading issue?

That's correct. We can (and do) call reloadAsync in multiple other places in the app just fine. It's only when this assets/font issue occurs at startup does a then manual call to reloadAsync throw the updates related error that is not seen elsewhere.

Until the root cause is fixed, we thought we could mask the issue (to the user) by using Updates.reloadAsync when a fontError (from useFonts) occurred, but quickly found it wouldn't work due to the mentioned issue.

All of these somehow stem from the assets/font issue where, completely randomly, the app will start and be unable to locate the asset/font file. So whatever is happening there is likely related to this other behavior. We see it maybe once per 10-15 app starts.

@douglowder
Copy link
Contributor

douglowder commented Oct 19, 2023

@nathantew14 to debug your issue, I would recommend catching the error that is returned by the useFonts() API. See the example here: https://docs.expo.dev/develop/user-interface/fonts/#use-a-google-font

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { useFonts, Inter_900Black } from '@expo-google-fonts/inter';

export default function App() {
  let [fontsLoaded, fontError] = useFonts({
    Inter_900Black,
  });

  if (!fontsLoaded && !fontError) {
    return null;
  }

  return (
    <View style={styles.container}>
      <Text style={{ fontFamily: 'Inter_900Black', fontSize: 40 }}>Inter Black</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

Then you can hide the splash screen when the font load either completes successfully, or completes with an error:

const onLayoutRootView = useCallback(async () => {
    if (fontsLoaded || fontError) {
        await SplashScreen.hideAsync();
    }
}, [fontsLoaded, fontError]);

@nathantew14
Copy link

@douglowder I actually tried to capture the error with Sentry and automatically restart the app on fontError, but for some reason the error is never captured by sentry and restarting doesn’t resolve the issue

in your suggestion you just hid the splashscreen upon error (which is essentially ignoring it, right?), but from the comments above it seems like a failure to load the fonts would indicate a failure to load all other assets?

@douglowder
Copy link
Contributor

@nathantew14 I am not suggesting that the error be ignored -- it does look like a failure to load all assets. I was just saying that it will help with debugging if you hide the splash screen when the error happens. In cases like this, I display the error in the UI as well.

If you hide the splashscreen and then have a useEffect that throws when the error happens, I think Sentry should hopefully be able to capture that.

@brunops
Copy link

brunops commented Oct 24, 2023

Hi, is there a solution for this? Expo app works fine with in Expo Go, but as soon as I make an ios build, the app in TestFlight freezes in the Splash Screen, not sure how debug this.

thanks

@tkoehlerlg
Copy link

@douglowder

@itsezc
Copy link

itsezc commented Jan 17, 2024

Tried all solutions suggested here, including loading from @expo-google-fonts - no luck on Expo 49. My CLI is throwing errors about this issue should remain open @douglowder.

@AlbertoAquinoDev
Copy link

Happens the same to me right now...

@aindong
Copy link

aindong commented Jan 20, 2024

This issue still happens on sdk 50

@douglowder
Copy link
Contributor

@itsezc @AlbertoAquinoDev @aindong do you have an Expo SDK 50 project that shows this issue? If so, please provide that and the steps you follow when observing the font loading bug (including whether the bug happens on iOS, Android, or both). If you can provide that, I'll create a new GitHub issue (as it is probably not the same as the problem originally happening in this issue).

@DutchPrince
Copy link

For me it works inside the RootLayout but not inside the Stack component thats loaded within

`
import * as SplashScreen from 'expo-splash-screen';

import {
useFonts,
Archivo_100Thin,
Archivo_200ExtraLight,
Archivo_300Light,
Archivo_400Regular,
Archivo_500Medium,
Archivo_600SemiBold,
Archivo_700Bold,
Archivo_800ExtraBold,
Archivo_900Black,
Archivo_100Thin_Italic,
Archivo_200ExtraLight_Italic,
Archivo_300Light_Italic,
Archivo_400Regular_Italic,
Archivo_500Medium_Italic,
Archivo_600SemiBold_Italic,
Archivo_700Bold_Italic,
Archivo_800ExtraBold_Italic,
Archivo_900Black_Italic,
} from '@expo-google-fonts/archivo';

function RootLayout() {
let [fontsLoaded, error] = useFonts({
'Archivo100Thin': Archivo_100Thin,
'Archivo200ExtraLight': Archivo_200ExtraLight,
'Archivo300Light': Archivo_300Light,
'Archivo400Regular': Archivo_400Regular,
'Archivo500Medium': Archivo_500Medium,
'Archivo600SemiBold': Archivo_600SemiBold,
'Archivo700Bold': Archivo_700Bold,
'Archivo800ExtraBold': Archivo_800ExtraBold,
'Archivo900Black': Archivo_900Black,
'Archivo100ThinItalic': Archivo_100Thin_Italic,
'Archivo200ExtraLightItalic': Archivo_200ExtraLight_Italic,
'Archivo300LightItalic': Archivo_300Light_Italic,
'Archivo400RegularItalic': Archivo_400Regular_Italic,
'Archivo500MediumItalic': Archivo_500Medium_Italic,
'Archivo600SemiBoldItalic': Archivo_600SemiBold_Italic,
'Archivo700BoldItalic': Archivo_700Bold_Italic,
'Archivo800ExtraBoldItalic': Archivo_800ExtraBold_Italic,
'Archivo900BlackItalic': Archivo_900Black_Italic,
});

const onLayoutRootView = useCallback(async () => {
    if (fontsLoaded && !error) {
        await SplashScreen.hideAsync();
    }
}, [fontsLoaded, error]);

if (!fontsLoaded && !error) {
    return null;
}

return (
            <View onLayout={onLayoutRootView} style={{
                flex: 1,
            }}>
                            <Stack screenOptions={{
                                headerShown: false,
                            }} />
                 
            </View>
)

}

export default RootLayout;`

@parkwherever
Copy link

@douglowder I got this issue straight off the bat with npx create-expo-app@latest -t tabs@50

@parkwherever
Copy link

It's from the root layout and I am seeing it only with the local font

  const [loaded, error] = useFonts({
    SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
    ...FontAwesome.font,
  });

though the icons also do not load (albeit not on the load path)

Commenting out SpaceMono enables the load of the FontAwesome font

@douglowder
Copy link
Contributor

@parkwherever thanks for the report. This seems like a different issue than the one originally posted here... is the font error happening every time? Please provide a repo with the code and assets to repro the issue.

@ganeshkumarburra
Copy link

Hi @douglowder
Any input on above issue, fonts are loading outside of the Navigation Container/Stack Screens.
But when we are using the fonts in the Screen components fonts are not working as expected.

App.js File

import React, { useCallback, useEffect, useState } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { View } from "react-native";
import { ThemeProvider } from "@shopify/restyle";
import Login from "./src/components/Authentication/Login";
import theme from "./src/theme";
import Signup from "./src/components/Authentication/Signup";
import { useFonts } from "expo-font";
import * as SplashScreen from 'expo-splash-screen';

const Stack = createNativeStackNavigator();

export default function App() {
  const [fontsLoaded, fontError] = useFonts({
    'LemonLove': require('./assets/fonts/LemonLove.ttf')
  });

  const onLayoutRootView = useCallback(async () => {
    if (fontsLoaded || fontError) {
      await SplashScreen.hideAsync();
    }
  }, [fontsLoaded, fontError]);

  if (!fontsLoaded && !fontError) {
    return <View>
      <Text>Fonts not loaded</Text>
    </View>
  }

  return (
    <ThemeProvider theme={theme}>
      <Text style={{  fontSize: 30, fontFamily: 'LemonLove' }}>Inter Black 3</Text>
      <NavigationContainer>
        <Stack.Navigator>
          <Stack.Screen
            name="login"
            component={Login}
            options={{ headerShown: false }}
          />
          <Stack.Screen
            name="register"
            component={Signup}
            options={{ headerShown: false }}
          />
        </Stack.Navigator>
      </NavigationContainer>
    </ThemeProvider>
  );
}

Signup Component:

import React from "react";
import { Box, SafeTopSpace, ScrollView, Text } from "../Common";
import { StyleSheet } from "react-native";

const Signup = () => {
  const styles = StyleSheet.create({
    heading: {
      fontFamily: "LemonLove",
      fontSize: 28,
      fontWeight: "700",
      lineHeight: 30,
      textAlign: "left",
    },
  });
  return (
    <Box
      flex={1}
      backgroundColor={"grayB"}
      height={500}
      paddingVertical={"m"}
      paddingHorizontal={"s"}
    >
      <SafeTopSpace />
      <Text color={"grayA"} style={styles.heading}>
        Lets Create a new Account
      </Text>
      <Text color={"grayC"}>Please fill in the data below</Text>
      <Box
        padding={"s"}
        marginVertical={"s"}
        borderRadius={"medium"}
        backgroundColor={"white"}
      ></Box>
    </Box>
  );
};

export default Signup;

Screenshot 2024-03-15 at 10 20 21 PM"

Thank you!

@douglowder
Copy link
Contributor

@ganeshkumarburra what happens if you use createStackNavigator() from @react-navigation/stack instead of the native-stack navigator?

@ganeshkumarburra
Copy link

Thank you @douglowder , For replying quickly.
It took sometime to me do test in the Existing App, there are some issues which i am facing after moving from native-stack to stack.

Then i created one more sample app to test this.
Now, i am able to Load the Fonts in Stack screens too.
But now i have one more challenge?
After moving the Stack Navigation which you mentioned, i am getting below error
ERROR TypeError: _RNGestureHandlerModule.default.flushOperations is not a function (it is undefined), js engine: hermes
Surprisingly, this issue comes when we click on reload (r), in expo app, but it will go away when we save any other .tsx file.
App.tsx

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import 'react-native-gesture-handler';
import { useFonts } from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import Home from './src/screens/home';
import { useCallback } from 'react';

SplashScreen.preventAutoHideAsync();
const Stack = createStackNavigator();

export default function App() {

  const [fontsLoaded, fontError] = useFonts({
    'LemonLove': require('./assets/fonts/LemonLove.ttf'),
  });

  const onLayoutRootView = useCallback(async () => {
    if (fontsLoaded || fontError) {
      await SplashScreen.hideAsync();
    }
  }, [fontsLoaded, fontError]);

  if (!fontsLoaded && !fontError) {
    return null;
  }
  
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={Home} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Home.tsx

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
export default function Home() {
    return (
      <View >
        <Text style={{fontFamily:"LemonLove"}}>Home Screen</Text>
      </View>
    );
  }

package.json

{
  "name": "lecturepedia",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "ts:check": "tsc"
  },
  "dependencies": {
    "@react-navigation/native": "^6.1.16",
    "@react-navigation/stack": "^6.3.28",
    "expo": "~50.0.13",
    "expo-font": "^11.10.3",
    "expo-splash-screen": "^0.26.4",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-native": "0.73.5",
    "react-native-gesture-handler": "^2.15.0",
    "react-native-safe-area-context": "^4.9.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.2.45",
   "typescript": "^5.1.3"
  },
  "private": true
}
Screenshot 2024-03-16 at 12 09 31 AM Screenshot 2024-03-16 at 12 09 47 AM

@douglowder
Copy link
Contributor

I believe you are supposed to import GestureHandlerRootView from the gesture handler package, and then wrap your app in the GestureHandlerRootView component. Example here: https://github.com/infinitered/ignite/blob/master/boilerplate/app/app.tsx

@chasem-dev
Copy link

chasem-dev commented May 13, 2024

Edit: Nevermind... I apologize for pinging everyone. I had my preventAutoHideAsync() running in the root index.tsx, but had the hideAsync() running in the root _layout.tsx

I noticed this happening today, on both SDK 50 and SDK 51. Get a false and null for fontsLoaded and fontError, but never get a response update after that, and I don't see anything in my console to explain what's going on. Seems like it's infinitely loading, or silently failing

@brentvatne
Copy link
Member

@chasem-dev - can you share a minimal reproducible example in a new issue?

@chasem-dev
Copy link

I apologize @brentvatne updated my comment just now, found a bug in my repo causing it 🤦

@pera14
Copy link

pera14 commented May 14, 2024

@brentvatne I'm having issue loading my font.

const [fontsLoaded, fontError] = useFonts({
		'nunito-semi-bold': require('./assets/fonts/Nunito-SemiBold.ttf'),
		'nunito-medium': require('./assets/fonts/nunito-medium.ttf'),
		'nunito-bold': require('./assets/fonts/nunito-bold.ttf'),
		'nunito-classic': require('./assets/fonts/nunito-classic.ttf'),
		nunito: require('./assets/fonts/nunito.ttf'),
	});

But I always get fontError on IOS:

Calling the 'loadAsync' function has failed
→ Caused by: Registering 'Error Domain=com.apple.CoreText.CTFontManagerErrorDomain Code=203 "Could not unregister the CGFont '<CGFont (0x600002c20b00): NunitoSans7pt-SemiBold>'" UserInfo={NSDescription=Could not unregister the CGFont '<CGFont (0x600002c20b00): NunitoSans7pt-SemiBold>', CTFailedCGFont=<CGFont (0x600002c20b00): NunitoSans7pt-SemiBold>}' 
font failed with message: 'The operation couldn’t be completed. (com.apple.CoreText.CTFontManagerErrorDomain error 203 - Could not unregister the CGFont '<CGFont (0x600002c20b00): NunitoSans7pt-SemiBold>')'

Do you have any idea how to solve this issue?

@slauzinho
Copy link

I'm having a similar issue using sdk 51 and expo-font 12.0.4 where the font initially loads fine, but the next time I re-open the app the fonts are no longer loaded.

@GaeDLLD
Copy link

GaeDLLD commented May 16, 2024

Same issue as you @pera14 and @slauzinho... Since I update my project to Expo 51 with react-native 0.74 and expo-font 12.04... My custom .otf font is loading and displaying as requested on the first dev build (but with the same dismissible error as @pera14). And when I fast-reload my app, the text loose the custom font family and all others text styles...

@slauzinho
Copy link

slauzinho commented May 16, 2024

I tried upgrading expo-font to 12.0.5 as now the bug seems to be different, before it was showing a default font, now the app just crashes with the error:

EXC_BAD_ACCESS: elvetica Neue Interface UltraLight P2 >
Attempted to dereference null **pointer.**

CleanShot 2024-05-16 at 13 05 04@2x

@pera14
Copy link

pera14 commented May 16, 2024

I did following and it's working for me now.

  1. I added expo-font and added following in app.json:
{
	"expo": {
		...
		"plugins": [
			...
			[
				"expo-font",
				{
					"fonts": [
						"./assets/fonts/nunito-semi-bold.ttf", 
						"./assets/fonts/nunito-medium.ttf", 
						"./assets/fonts/nunito-bold.ttf", 
						"./assets/fonts/nunito-classic.ttf", 
						"./assets/fonts/nunito.ttf"]
				}
			]
		],
    }
}
  1. I used useFonts:
const [fontsLoaded, fontError] = useFonts({
		'nunito-semi-bold': require('./assets/fonts/nunito-semi-bold.ttf'),
		'nunito-medium': require('./assets/fonts/nunito-medium.ttf'),
		'nunito-bold': require('./assets/fonts/nunito-bold.ttf'),
		'nunito-classic': require('./assets/fonts/nunito-classic.ttf'),
		nunito: require('./assets/fonts/nunito.ttf'),
	});

But I start the app even if an error occurs, since the font will be loaded in runtime. This solution works for me so far.

@GaeDLLD
Copy link

GaeDLLD commented May 16, 2024

I did following and it's working for me now.

  1. I added expo-font and added following in app.json:
{
	"expo": {
		...
		"plugins": [
			...
			[
				"expo-font",
				{
					"fonts": [
						"./assets/fonts/nunito-semi-bold.ttf", 
						"./assets/fonts/nunito-medium.ttf", 
						"./assets/fonts/nunito-bold.ttf", 
						"./assets/fonts/nunito-classic.ttf", 
						"./assets/fonts/nunito.ttf"]
				}
			]
		],
    }
}
  1. I used useFonts:
const [fontsLoaded, fontError] = useFonts({
		'nunito-semi-bold': require('./assets/fonts/nunito-semi-bold.ttf'),
		'nunito-medium': require('./assets/fonts/nunito-medium.ttf'),
		'nunito-bold': require('./assets/fonts/nunito-bold.ttf'),
		'nunito-classic': require('./assets/fonts/nunito-classic.ttf'),
		nunito: require('./assets/fonts/nunito.ttf'),
	});

But I start the app even if an error occurs, since the font will be loaded in runtime. This solution works for me so far.

This is what I already did, but still not working after refresh. And custom font not working at all on Android...

@anstap
Copy link

anstap commented May 17, 2024

Have the same issue using Icomoon font and did the steps in the reply above no luck, still fails. It seems to be failing in production build uncontrollably and on the iOS simulator when the hot-refresh happens.

And btw I'm on expo 51 😅

@vbylen
Copy link

vbylen commented May 19, 2024

happens on every reload of the simulator

image

@aleqsio
Copy link
Contributor

aleqsio commented May 20, 2024

@vbylen I think this PR should fix the error 203 issue:
#28989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests