expo / expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
https://docs.expo.dev
MIT License
32.03k stars 5.08k forks source link

expo-font connection error when trying to load fonts from assets while offline. #17602

Closed AlenToma closed 1 year ago

AlenToma commented 2 years ago

Summary

As the titles says, I am trying to load the cached fonts assets while missing the internet eg in airplane mode. it says connection error, it is trying to validate if there is an internet available to get access to, but I am not adding any URL.

I am loading it from the cached asset. ``

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44.0.2

Environment

  expo-env-info 1.0.3 environment info:
    System:
      OS: Windows 10 10.0.19044
    Binaries:
      Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 8.10.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version     2021.1.0.0 AI-211.7628.21.2111.8193401
    npmPackages:
      expo: ^44.0.2 => 44.0.6
      react: 17.0.1 => 17.0.1
      react-dom: 17.0.1 => 17.0.1
      react-native: 0.64.3 => 0.64.3
    Expo Workflow: bare

Reproducible demo

Here is a component that I build that show the problem.

import * as React from 'react'
import { StyleProp, TextStyle, Text } from 'react-native'
import AntDesign from '@expo/vector-icons/AntDesign'
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
import Ionicons from '@expo/vector-icons/Ionicons'
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
import Entypo from '@expo/vector-icons/Entypo'
import Feather from '@expo/vector-icons/Feather'
import FontAwesome5 from '@expo/vector-icons/FontAwesome5'
import FontAwesome from '@expo/vector-icons/FontAwesome'
import Fontisto from '@expo/vector-icons/Fontisto'
import EvilIcons from '@expo/vector-icons/EvilIcons'
import * as Font from 'expo-font';
const IconTypeArray = {
    AntDesign,
    MaterialCommunityIcons,
    Ionicons,
    MaterialIcons,
    Entypo,
    Feather,
    Fontisto,
    FontAwesome5,
    FontAwesome,
    EvilIcons
} as any;

type ElementType = "AntDesign" | "MaterialCommunityIcons" | "Ionicons" | "MaterialIcons" | "Entypo" | "Feather" | "FontAwesome5" | "FontAwesome" | "Fontisto" | "EvilIcons";

export default (props: { type: ElementType, name: string, size?: number, color?: string, style?: StyleProp<TextStyle> }) => {
    const Icon = IconTypeArray[props.type];
    const pType = { ...props } as any;
    const [loaded] = Font.useFonts({
        ...Icon.font
      });
    delete pType.type;

    if (!loaded)
        return <Text>Loading</Text>
    return (
        <Icon {...pType} />
    )
}

simple call the components

<Icon type="Ionicons" name='md-reload-circle' size={20} color="red" />

and in my app-json

    "assetBundlePatterns": [
      "./node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/*"
    ],
artanisdesign commented 2 years ago

Hi! I'm experiencing the same. using EAS build, also with OTA updates. I can see the fonts properly bundled into the package, but useFonts wont resolve (nor loadAsync) in offline, therefore loading wont proceed. if i removed the useFonts/loadAsync part, app started okay in offline, but without the fonts ofcourse.

Screenshot 2022-05-23 at 14 44 16

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

jameswilddev commented 1 year ago

I am also seeing this - TTFs are definitely in the APK, but expo-font seemingly can't find them in the cache.

This is one of a slew of issues we're having moving to EAS, can the migration away from Turtle be postponed, preferably indefinitely?