You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created an react-native/typescript app with expo CLI, this generate some base code, inlcuding hooks/useCachedResources to load any resources or data that we need prior to rendering the app, in my case in this hook I load custom fonts(in particular Inter Display Font). I'm experimenting some problems because the app loads only two weights: regular and medium, If I try to use semi-bold or bold this doesnt work and use the san serif font that comes by default.
Additional data:
The fonts path its ok
Expo app doesn't show any error. I have seen in other questions errors such as fontFamily "MyFontFamily" is not a system font and has not been loaded through Font.loadAsync. This is not the case.
Font family name is in the correct format.
I'm using React Native UI Kitten and I load the fonts as they suggest in Advanced Configuration and change some especific styles.
According to some answers The out of the box support for custom fonts on Android is a little limited in React Native. It does not support font weights other than normal and bold. So I tried setting fontWeight: normal or any of the weights but nothing works.
useCachedResources hook
This come by default with expo init my-app.
import*asFontfrom'expo-font';import*asSplashScreenfrom'expo-splash-screen';import{useEffect,useState}from'react';// Error reporting serviceimport{logger}from'@utils';exportfunctionuseCachedResources(): boolean{const[isLoadingComplete,setLoadingComplete]=useState(false);// Load any resources or data that we need prior to rendering the appuseEffect(()=>{asyncfunctionloadResourcesAndDataAsync(){try{awaitSplashScreen.preventAutoHideAsync();// Load fontsawaitFont.loadAsync({'inter-display-regular': require('../assets/fonts/InterDisplay-Regular.ttf'),'inter-display-medium': require('../assets/fonts/InterDisplay-Medium.ttf'),'inter-display-semibold': require('../assets/fonts/InterDisplay-SemiBold.ttf'),'inter-display-bold': require('../assets/fonts/InterDisplay-Bold.ttf'),});}catch(loadCachedResourcesError){logger.log(loadCachedResourcesError);}finally{setLoadingComplete(true);awaitSplashScreen.hideAsync();}}loadResourcesAndDataAsync();},[]);returnisLoadingComplete;}
Consuming the hook in App.tsx
import{StatusBar}from'expo-status-bar';importReactfrom'react';import{SafeAreaProvider}from'react-native-safe-area-context';importuseCachedResourcesfrom'./hooks/useCachedResources';importNavigationfrom'./navigation';// again this comes by defautl expo init commandexportdefaultfunctionApp(): React.ReactElement|null{constisLoadingComplete=useCachedResources();if(!isLoadingComplete){returnnull;}return(<SafeAreaProvider><Navigation/><StatusBar/></SafeAreaProvider>);}
mapping.json: specific UI-Kitten configuration to change font style
I can think that the problem comes from here but the thing is, if there was a problem loading the fonts, either expo would have already thrown an error or the other fonts weights(regular/medium) would not load.
Create and configuring Metro Bundler as UI Kitten documentation reccomends.
Expected behavior
If two typography weights are loaded correctly, why are the other two weights are not loaded? all sizes are expected to load and be usable as normal throughout the app. I don't know if the problem comes from expo, although I don't think this is the problem because then the other two sizes wouldn't load, or the problem is caused by UI Kitten.
Link to runnable example or repository (highly encouraged)
@Cristian05
Did you try to apply the custom font to the usual Text component with fontWeight: "normal" or fontWeight: "bold"?
We had a similar issue #1399 so it might be just related to font/react-native.
@malashkevich
Yes I did, fontWeight: "normal" works, the problem is, are only being loaded medium and regular weights. Semibold and Bold are missing. neither the console or expo shown any error.
🐛 Bug Report
I have created an
react-native/typescript
app withexpo CLI
, this generate some base code, inlcudinghooks/useCachedResources
to load any resources or data that we need prior to rendering the app, in my case in this hook I load custom fonts(in particular Inter Display Font). I'm experimenting some problems because the app loads only two weights:regular and medium
, If I try to usesemi-bold
orbold
this doesnt work and use the san serif font that comes by default.Additional data:
fontFamily "MyFontFamily" is not a system font and has not been loaded through Font.loadAsync.
This is not the case.Advanced Configuration
and change some especific styles.fontWeight: normal
or any of the weights but nothing works.useCachedResources hook
This come by default with
expo init my-app
.Consuming the hook in App.tsx
mapping.json: specific UI-Kitten configuration to change font style
I can think that the problem comes from here but the thing is, if there was a problem loading the fonts, either expo would have already thrown an error or the other fonts weights(regular/medium) would not load.
The problem
I have no idea if the problem comes from
expo
,ui kitten
or ifinter
font can't be loaded by react native by some other reason.To Reproduce
expo init my-app
and add UI kitten as dependency.App
component wrap the navigation withApplicationProvider
like so:Expected behavior
If two typography weights are loaded correctly, why are the other two weights are not loaded? all sizes are expected to load and be usable as normal throughout the app. I don't know if the problem comes from
expo
, although I don't think this is the problem because then the other two sizes wouldn't load, or the problem is caused by UI Kitten.Link to runnable example or repository (highly encouraged)
UI Kitten and Eva version
Environment information
The text was updated successfully, but these errors were encountered: