Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

React Native Expo, custom fonts

fontFamily "SF-Regular" is not a system font and has not been loaded through Font.loadAsync.

- If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.

- If this is a custom font, be sure to load it with Font.loadAsync.

Im getting this error even though I have this code below, it was working yesterday

let [fontsLoaded] = useFonts({
        'SF-Black': require('./assets/fonts/SF-Black.otf'),
        'SF-Bold': require('./assets/fonts/SF-Bold.otf'),
        'SF-Regular': require('./assets/fonts/SF-Regular.otf'),
        'SF-Light': require('./assets/fonts/SF-Light.otf'),
    });

Im using managed workflow SDK 39 "@use-expo/font": "^2.0.0", "expo": "~39.0.2", "expo-av": "^8.6.0", "expo-font": "^8.3.0",

''' import React, { useState, useEffect, useRef } from 'react'; import { AntDesign, FontAwesome, MaterialIcons, FontAwesome5 } from '@expo/vector-icons'; import { Text, View,Dimensions, ActivityIndicator} from 'react- import { useFonts } from 'expo-font'; import * as Font from 'expo-font';

    const Tab = createBottomTabNavigator();
    
    let fonts = {
      'SF-Black': require('./assets/fonts/SF-Black.otf'),
    };

    export default function App() {
    
      const loadFontsAsync = async () => {
        Font.loadAsync(fonts).then(() => {
          setFont(true)
        })
      }
    
      const [fontsLoaded, setFont] = useState(false);
    
      useEffect(() => {
        loadFontsAsync();
      }, [])
    
      const [appState, setAppState] = useState(AppState.currentState);
    
      const [refresh, setRefresh] = useState(false);
    
      const handleAppStateChange = (nextAppState) => {
        setAppState(nextAppState);
        if (refresh) {
          setRefresh(false);
        } else {
          setRefresh(true);
        }
      }
     
    

      if (!fontsLoaded) {
        return (
            <ActivityIndicator size='large' color='white' />
        );
      } else {
        return (
          <NavigationContainer theme={MyTheme}>
            <Tab.Navigator
              initialRouteName="Home"
              tabBarOptions={{ 
                activeTintColor: selectColor,
                inactiveTintColor: unselectColor,
                style:{height: ScreenHeigth * 0.1},
              }}>
              <Tab.Screen
                name="Youtube"
                component={Youtube}
                options={{
                  tabBarLabel: 'Videos',
                  tabBarIcon: ({ color, size }) => (
                    <AntDesign name="youtube" size={size} color={color} />
                  ),
                }}  />
      
                  
            </Tab.Navigator>
          </NavigationContainer>
        );
       
      }
    
    }

'''

This is from App.js

question from:https://stackoverflow.com/questions/65907480/react-native-expo-custom-fonts

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...