在react native expo项目中导入自定义字体时面临的问题

lkaoscv7  于 6个月前  发布在  React
关注(0)|答案(1)|浏览(75)

我试图在react native expo项目中导入名为raleway的自定义谷歌字体。即使在运行项目时遵循expo字体文档,我也会收到错误字体Family 'raleway'不是系统字体,并且尚未通过Font. loadAsync加载。
以下是我如何导入App.js文件中的字体-

import { useFonts } from 'expo-font';
let customFonts={
    'raleway':require('./assets/Fonts/Raleway-Regular.ttf')
  }

  const [isLoaded]=useFonts(customFonts)

字符串
我在另一个文件GoogleMapView.js文件中使用它-

text:{
      fontWeight:"bold",
      fontSize:16,
      marginBottom:10,
      fontFamily:"raleway"
    }

jgwigjjp

jgwigjjp1#

像这样在App.js上导入字体

import AppLoading from 'expo-app-loading';
import { useFonts } from 'expo-font';
let customFonts = {
'raleway':require('./assets/Fonts/Raleway-Regular.ttf')
};

const App = () => {
const [isLoaded] = useFonts(customFonts);
if (!isLoaded) {
return <AppLoading />;
}
return <RootApp />;
}

字符串

相关问题