0

I have the following files added in the android/src/main/assets folder.

Poppins-Bold.ttf
Poppins-Regular.ttf
Poppins-Light.ttf
Poppins-Medium.ttf
Poppins-MediumItalic.ttf

When applying font-family as follows in my stylesheet

header: {
  fontFamily: 'Poppins',
  fontWeight: '700'
}

This works fine on iOS but the font-family is not applied on Android. After going through some answers provided, I figured out we could apply the following directly and it'll work

header: {
  fontFamily: 'Poppins-Bold',
}

This works on both Android and iOS. But the problem here is, if I want to give my devs control on font-weight with this custom font, can't do that.

Is there no way to, say maybe combine all ttf's to one ttf and use it with font-weight or some efficient way to fix this in Android?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ws7one
  • 56
  • 6

1 Answers1

0

you can follow step to do this

make js file react-native.config.js

module.exports = {
project: {
    ios: {},
    android: {},
},
assets: ['../../assets/fonts'],
};

then make fonts folder inside android assets and copy all

enter image description here

enter image description here

End in js file used font like

 txtLoginDescription: {
    color: COLORS.F_1E1F22,
    fontSize: 12,
    width: '100%',
    textAlign: 'center',
    fontFamily: 'Montserrat-Regular',
    fontWeight: '400',
    marginTop: 15
},
mehul chauhan
  • 1,792
  • 11
  • 26
  • I have done what you have mentioned here. If I am not wrong, if you apply `fontWeight: "700"` it should not work, since the fontFamily 'Montserrat-Regular' does not have glyphs for font weight above 700. – Ws7one Jul 04 '22 at 12:02
  • Montserrat-Regular is my app fonts you can used your font Poppins-Bold – mehul chauhan Jul 04 '22 at 12:22
  • I understood that. What I meant is if I use Poppins-Bold and use fontWeight: "400", it's not going to give me a font that looks like Poppins-Regular. Android does not seem to work that way. In iOS you can simply say fontFamily: 'Poppins' and whatever fontWeight you want and it picks the right font-family automatically. But Android does not do that? – Ws7one Jul 05 '22 at 15:37
  • Does using `fontFamily: "Montserrat-Regular"` with `fontWeight: "700"` give you a "Bold" font? Is that working for you? – Ws7one Jul 05 '22 at 15:38