我目前正在尝试为我的应用程序加载自定义字体。 iOS 的字体加载正确,但 Android 上出现以下错误
[Error: The method or property expo-file-system.downloadAsync is not available on android, are you sure you've linked all the native dependencies properly?]
我正在使用 expo-font 在应用程序启动时加载谷歌字体
使用@expo-google-fonts/montserrat
下面是不起作用的代码片段。目前适用于 iOS 应用程序。
import { useFonts } from 'expo-font'
const [fontsLoaded, fontError] = useFonts(fontsUtils.customFontsToLoad)
if (!fontsLoaded || fontError) {
console.log('ERROR => ', fontError)
return (
<View
style={{
flex: 1,
backgroundColor: colors.black,
alignItems: 'center',
justifyContent: 'center',
}}
>
<ActivityIndicator color={colors.white} size={'large'} />
</View>
)
}
这是 customFontsToLoad 的代码
const customFontsToLoad = {
Montserrat_100Thin,
Montserrat_200ExtraLight,
Montserrat_300Light,
Montserrat_400Regular,
Montserrat_500Medium,
Montserrat_600SemiBold,
Montserrat_700Bold,
Montserrat_800ExtraBold,
Montserrat_900Black,
Montserrat_100Thin_Italic,
Montserrat_200ExtraLight_Italic,
Montserrat_300Light_Italic,
Montserrat_400Regular_Italic,
Montserrat_500Medium_Italic,
Montserrat_600SemiBold_Italic,
Montserrat_700Bold_Italic,
Montserrat_800ExtraBold_Italic,
Montserrat_900Black_Italic,
Mulish_200ExtraLight,
Mulish_300Light,
Mulish_400Regular,
Mulish_500Medium,
Mulish_600SemiBold,
Mulish_700Bold,
Mulish_800ExtraBold,
Mulish_900Black,
Mulish_200ExtraLight_Italic,
Mulish_300Light_Italic,
Mulish_400Regular_Italic,
Mulish_500Medium_Italic,
Mulish_600SemiBold_Italic,
Mulish_700Bold_Italic,
Mulish_800ExtraBold_Italic,
Mulish_900Black_Italic,
}
已检查所有导入,似乎设置正确。有人可以阐明我做错了什么吗?预先感谢
你必须先加载字体,也许在 App.tsx 中
import * as Font from 'expo-font';
let customFonts = {
'Inter-Black': require('./assets/fonts/Inter/Inter-Black.otf'),
'Inter-Medium': require('./assets/fonts/Inter/Inter-Medium.otf'),
'Inter-Regular': require('./assets/fonts/Inter/Inter-Regular.otf')};
// useEffect
await Font.loadAsync(customFonts);