6

I am trying to use a font "Verveine Corp Regular' inside my react-native app.

The font works in the iOS build, but not in the Android build.

The font is in .tff format and is placed in the root of my work (linked in the package.json and I have run react-native link) and inside "android/gradle/src/main/assets/fonts" but it's still not picking the font up. I have also cleaned and rebuilt the app multiple times.

When inspecting an element which uses the font in the android debugger, it says it's using the font. But the font is still the default font.

Could anyone offer some help or guidance on this issue?

Thanks!

Jake K
  • 75
  • 1
  • 7

6 Answers6

4

The other answers helped me get this working for me, thank you. This manuever is probably only necessary when the font has capital letters in the filename. A more complete answer:

Add the font as normal in react native, for example:

{react-native-project}/fonts/GovtAgentBB.ttf

Run react-native link and this will put the font in

{react-native-project}/android/app/src/main/assets/fonts/GovtAgentBB.ttf

{react-native-project}/android/app/src/main/assets/fonts/GovtAgentBB_ital.ttf

But android, bring robotic and not human, doesn't like this. So rename the file with all lower case letters and an underscore before the variant, like:

{react-native-project}/android/app/src/main/assets/fonts/govtagentbb.ttf

{react-native-project}/android/app/src/main/assets/fonts/govtagentbb_ital.ttf

Then, you have to change the font name in the style depending on the platform. For iOS, use the human name that is the name of the font that would be displaying in the title of the window of the Mac Font menu (or just the name you see on the web). For android, you have to, robotically, use the name of the file you just renamed.

      {Platform.OS === 'ios' ? (
        <Text style={styles.welcome}>
          Hello World!
        </Text>
      ) : (
        <Text style={styles.welcomeAndroid}>
          Hello World
        </Text>
      )}
      const styles = StyleSheet.create({
      ...
      welcome: {
          fontFamily: 'Government Agent BB',
      },
      welcomeAndroid: {
          fontFamily: 'govtagentbb',
      },
Michael Bushe
  • 1,503
  • 16
  • 16
3

This is how I used custom font in my project

//sampleStyle.js
import overrideStyles from '/sampleoverridestyles';
iconTextStyle: {
  color: '#FFFFFF',
  fontSize: 16
}

//sampleoverridestyles.ios.js
export default {
  iconTextStyle: {
    fontFamily: 'FaktSoftPro-Medium'
  }
}

//sampleoverridestyles.android.js
export default {
  iconTextStyle: {
    fontFamily: 'faktsoftpro_medium'
  }
}

since I cannot set the font name same for iOS and android I have overridden it as above and it worked.

arjun
  • 3,514
  • 4
  • 27
  • 48
3

Guys if you are following all other solution and still no update then try following the steps

  1. add react-native-config.js file
  2. then add fonts in assets/fonts/your font
  3. rename it with lowercase like OpenSans_Regular to opensans_regular
  4. react-native link in terminal in your project folder
  5. after all build your project again using react-native run-android
  6. fontFamily: Platform.OS === "ios" ? 'opensans_regular' : 'cassandrapersonaluseregular_3bjg',

I was also getting the same issue the font was not reflecting changes then I build my project again that was my mistake because we adding fonts in our android folder so we need to compile that again. I hope someone may save their time

2

I added font in react-native android from here:

https://medium.com/@gattermeier/custom-fonts-in-react-native-for-android-b8a331a7d2a7#.40vw3ooar

Follow all the steps it will work fine.

After adding run react-native run-android

Ankush Rishi
  • 2,861
  • 8
  • 27
  • 59
1
First, make sure you are up to version 0.16+ with react-native.
Your fonts should be *.ttf or *.otf files and must be located in: /projectname/android/app/src/main/assets/fonts
Make sure the fonts are lowercase only and follow this pattern: fontname.ttf, fontname_bold.ttf, fontname_light.ttf, fontname_bold_italic.ttf
Nitesh Mishra
  • 574
  • 1
  • 6
  • 14
1

Have you defined another font in your AppTheme (styles.xml), that overrides your preferred font?

Have you tested your font with a "Hello World"-App as a minimal test?

Have you implemented your ttf as shown here for example?: How to use custom font in Android Studio

Community
  • 1
  • 1
tigercode
  • 67
  • 7
  • Yep, I have just tried all these but nothing. When I inspect the element in the android debugger, it says the element is using the font I want it to. But the element is still displaying as the default font. – Jake K Mar 02 '17 at 12:38