question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom fontFamily does not work with Text Heading (h1, h2, h3, h4)

See original GitHub issue

I’m loading a custom font using Expo as described here.

Setting the new font as fontFamily style works in regular Text components.

However, as soon as one of the heading props are set on the Text component, the fontFamily is no longer applied.

Example:

import { Text } from 'react-native-elements'

<Text
  h1
  h1Style={{ color: 'red', fontFamily: 'dosis-regular' }}
  style={{ color: 'blue', fontFamily: 'dosis-regular' }}
>This is my text</Text>

This text is large, red and uses the default font. After removing the h1 prop, the text is small, blue and using the Dosis font.

Keeping h1 but removing h1Style, the text is large, blue and using the default font. Keeping h1 but removing style does nothing.

Environment:

software version
react-native-elements 1.2.7
react-native 0.59.10
expo 35.0.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
pothos-devcommented, Nov 23, 2019

Setting fontWeight: 'normal' seems to fix the issue. Loading and setting the Bold variant of the font however doesn’t seem to make any difference, unless the fontWeight is also changed (the custom font ONLY shows up with normal fontWeight).

Maybe the information about which “weight” the font has is getting lost when loaded by expo-font, and all fonts are handled as regular.

For now, I’ll change the default fontWeight of all h-elements in the ThemeProvider, thanks!

3reactions
oxyiicommented, Nov 23, 2019

@bearbytes I’m not sure about exactly REGULAR fonts for using with h* props… https://github.com/react-native-elements/react-native-elements/blob/0f06b924fc7536f7599aca268864a75f33e13b1e/src/text/Text.js#L29-L32 Please try to use BOLD font… Or set fontWeight as normal inside h1Style

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adjust Heading Styles with Custom Design (h1, h2, h3, etc)
I'm having problems getting different fonts to work for the H3/H4 headers, though. I'm trying to use some of the other fonts that...
Read more >
How to Add and Apply Custom Fonts to Squarespace 7.1
Scroll down and find the button that says Manage Custom Files. Click Add Images or Fonts, and select your font file from the...
Read more >
How To Style Text Elements with Font, Size, and Color in CSS
You will work with different heading levels ( h1 - h6 ) and content types ( p , strong , and em )...
Read more >
Page Title and Heading different font from rest of site
Hello. I just added the CSS code below to change the font to my entire website (I am using the Storefront theme). After...
Read more >
Can I customise the header tags(h1,h2,h3...) in redactor editor?
You can format the text by adding CSS! By adding classes to the elements, you could style them like you want to. See...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found