Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

481
Visualizações
React Native Expo: Custom Fonts Not Loading Along With Google Fonts

I'm trying to load downloaded fonts along with google fonts using Font.loadAsync but it is giving me error:

Unable to resolve module ../../assets/fonts/sf-ui-text/SFUIText-Bold.ttf from /Users/bilal/Work/datumbrain/erp-app/src/utils/useFonts.js:

None of these files exist:
  * SFUIText-Bold.ttf
  * assets/fonts/sf-ui-text/SFUIText-Bold.ttf/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.svg|.native.svg|.svg)

Here is my code in App.js:

import { useCallback, useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Provider } from 'react-redux';
import colors from './src/constants/colors';
import AppNavigator from './src/navigation/AppNavigator';
import { store } from './src/redux/store';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import {
  FiraSans_300Light,
  FiraSans_400Regular,
  FiraSans_500Medium,
} from '@expo-google-fonts/fira-sans';
import { useFonts } from './src/utils/useFonts';

const App = () => {
  const [appIsReady, setAppIsReady] = useState(false);
  const prepare = async () => {
    try {
      const customFonts = await useFonts();
      await SplashScreen.preventAutoHideAsync();
      await Font.loadAsync({
        'Fira Sans 300': FiraSans_300Light,
        'Fira Sans 400': FiraSans_400Regular,
        'Fira Sans 500': FiraSans_500Medium,
        ...customFonts,
      });
    } catch (e) {
      console.warn(e);
    } finally {
      setAppIsReady(true);
      console.log('Loaded fonts...');
    }
  };
  const onLayoutRootView = useCallback(async () => {
    if (appIsReady) {
      await SplashScreen.hideAsync();
    }
  }, [appIsReady]);
  useEffect(() => {
    prepare();
  }, []);
  useEffect(() => {
    onLayoutRootView();
  }, [onLayoutRootView]);

  if (!appIsReady) {
    return null;
  }

  return (
    <Provider store={store} style={styles.container}>
      <AppNavigator />
    </Provider>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: colors.light,
    alignItems: 'center',
    justifyContent: 'center',
  },
});
export default App;

and useFonts.js:

import * as Font from 'expo-font';

export const useFonts = async () => {
  await Font.loadAsync({
    SF: require('../../assets/fonts/sf-ui-text/SFUIText-Bold.ttf'),
  });
};
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

Please make sure the path here is correct

SF: require('../../assets/fonts/sf-ui-text/SFUIText-Bold.ttf')

For the Font.loadAsync, it looks perfect to me. For extra, you could use useFont hook to make your handling looks better. (It uses Font.loadAsync underneath)

about 4 years ago · Santiago Gelvez Relatório

0

  1. Сheck the file path, this error occurs when the path is invalid.
  2. Your useFonts function doesn't return anything, so you don't need spread in prepare(). If it is called fonts will be loaded anyway.
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda