React Native Expo Google Fonts:不是系统字体,尚未通过 Font.loadAsync 加载

Jat*_*t90 4 fonts react-native expo

我正在使用 Expo Google Fonts 和 useFonts() 方法为我的应用程序导入字体。但是我收到以下错误,但我认为我不需要将 Font.loadasync 与 Google Fonts 一起使用(根据此处的文档)。你能让我知道我在这里做错了什么吗?

import React, { useState } from "react";
import { View, TouchableOpacity, Text, StyleSheet, Platform } from 'react-native'
import { useFonts, Kanit_400Regular, Kanit_500Medium, Kanit_700Bold } from '@expo-google-fonts/kanit';
import Colors from '../constants/Colors'

const Header = props => {

  useFonts({Kanit_400Regular, Kanit_500Medium, Kanit_700Bold})

  return (
    <View style={styles.headerContainer}>
      <View style={styles.logo}>
        <Text style={styles.headerText}>HEADER</Text>
      </View>
      <View>
        <Text style={{...styles.headerText, fontSize: 14 }}>LOGIN</Text>
      </View>
    </View>
  )
} 

const styles = StyleSheet.create({
  headerContainer: {
    padding: 15,
    paddingTop: Platform.OS === 'android' ? 40 : 15,
    backgroundColor: 'rgba(0,0,0,0.3)',
    justifyContent: 'space-between',
    height: Platform.OS === 'android' ? '12%' : '10%',
    borderBottomColor: Colors.borderGold,
    borderBottomWidth: 1,
    alignItems: 'center',
    flexDirection: 'row',
    fontSize: 16,
  },
  headerText: {
    fontSize: 16,
    color: Colors.primary,
    fontFamily: 'Kanit_500Medium',
  }
})

export default Header
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 6

就我而言,问题是expo-fontpackage.json 中的版本与安装的 expo 版本不兼容。

我从 降级10.1.0到10.0.4,字体现在加载正常。

记得使用expo install expo-font

我希望这有帮助