If you came here, you have probably already looked at the following information from stackoverflow How to add fonts for different font weights for react-native android project? and may have received errors related to ReactFontManager
I don’t know why this happened, but there is another option to do about the same thing, but it worked for me.
To begin with, we do the same thing as before, before creating the xml file, follows this instruction Add a font as an XML resource, it repeats the instruction with stackoverlow for the most part and coincides with it
Instead of using com.facebook.react.views.text.ReactFontManager;
what became deprecated Android: expose ReactFontManager as a standalone target (#38506) we will import com.facebook.react.common.assets.ReactFontManager
, and it’s finish
Edit app\android\app\src\main\java\com\youpackage\MainApplication.kt
//...
import com.facebook.react.common.assets.ReactFontManager
//...
class MainApplication : Application(), ReactApplication {
//...
override fun onCreate() {
super.onCreate()
//...
ReactFontManager.getInstance().addCustomFont(this, "Gilroy", R.font.gilroy);
//...
}
}
Leave a Reply