that is my app in github:
https://github.com/Ammar0203/expo
why my expo-react-native app’s fonts don’t work on android but on web it works fine
it says :
(fontFamily "DMRegular" is not a system font
and has not been loaded through Font.loadAsync.
-
If you intended to use a system font, make sure you typed the name correctly and that it is supported
by your device operating system. -
If this is a custom font, be sure to load it with
Font.loadAsync.)
it says that for all of the fonts i have searched all the web for a solution non of them worked
i’m coding that from a youtube tutorial (Build and Deploy a React Native App | 2023 React Native Course Tutorial for Beginners)
https://www.youtube.com/watch?v=mJ3bGvy0WAY&t=418s
i have reached to ( 40:58 ) in the video
import { Stack } from "expo-router";
import { useCallback } from "react";
import { useFonts } from "expo-font";
import * as SplashScreen from 'expo-splash-screen'
SplashScreen.preventAutoHideAsync()
const Layout = () => {
const [fontsLoaded] = useFonts({
DMBold: require('../assets/fonts/DMSans-Bold.ttf'),
DMMedium: require('../assets/fonts/DMSans-Medium.ttf'),
DMRegular: require('../assets/fonts/DMSans-Regular.ttf'),
})
const onLayoutRootView = useCallback(async () => {
if(fontsLoaded) {
await SplashScreen.hideAsync()
}
}, [fontsLoaded])
if(!fontsLoaded) {
return null
}
return <Stack onLayout={onLayoutRootView} />
}
export default Layout
I have tried adding ‘react-native.config.js’ and i tried the old way Fonts.loadAsync()
also i did not add fontWeight property in my stylesheet and also i tried deleting my node_modules folder
2
Answers
I have fixed it my terminal showed me that i need to fix the versions of my modules it said: "Some dependencies are incompatible with the installed expo version: [email protected] - expected version: ~11.4.0 [email protected] - expected version: 0.72.5 Your project may not work correctly until you install the correct versions of the packages. Fix with: npx expo install --fix"
so all i had to do is run in the terminal "npx expo install --fix"
I think you have your file added incorrectly. It is
react-native.config.js
at the root of your project and you are showingreact-native-config.js.
.Documentation showing as such here.