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.

H1 doesn't render fontFamily on Android

See original GitHub issue

👋🏽
Hello! I’m implementing a simple header in my app and it seems like Android is not rendering the font properly

iOS Screen Shot 2021-10-09 at 1 41 09 PM

Android Screen Shot 2021-10-09 at 1 41 03 PM

import { H1, Theme } from 'dripsy'
import theme from './theme'

// simplified example
const App = () => (
  <DripsyProvider theme={theme}>
    <H1>Hello world</H1>
  </DripsyProvider>
)
import { Theme } from 'dripsy'

const makeTheme = <T extends Theme>(t: T): T => t

const theme = makeTheme({
  fonts: {
    root: 'nunito',
  },
  customFonts: {
    nunito: {
      bold: 'nunitoBold',
      default: 'nunito',
      normal: 'nunito',
      400: 'nunito',
      500: 'nunitoSemiBold',
      600: 'nunitoBold',
      700: 'nunitoBold',
      800: 'nunitoExtraBold',
      900: 'nunitoBlack',
    },
  },
  text: {
    default: {
      fontSize: 18,
      color: 'text',
    },
    h1: {
      fontSize: [24, 32],
      color: 'text',
    },
  },
})

export default theme

I’ve noticed if I commented this line out in @expo/html-elements, it starts to work: https://github.com/expo/expo/blob/master/packages/html-elements/src/elements/Headings.tsx#L39

I’ve tried debugging the code in my node modules but still can’t figure it out. It’s weird that it works perfectly fine in iOS, but not in Android 🤔

Any help is appreciated!

In the meantime, my workaround is

<H1 as={Text} >Hello world</H1>

and it’s still able to pull variant “text.h1” 👍🏽

Thank you!!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nandorojocommented, Oct 26, 2021

For now, I recommend making your own H1, …etc text components, like so:

import { Text } from 'dripsy'

const H1 = (props: React.ComponentProps<typeof Text>) => (
  <Text
    {...props}
    variant="h1"
    accessibilityRole="heading"
    accessibilityLevel={1}
  />
)

I’ll work on a better internal solution that supports Android soon. However, we should open an issue at @expo/html-elements, since that’s where the bug lies.

0reactions
nandorojocommented, Oct 9, 2021

I mean this

<H1 as={Text} >Hello world</H1>

still had the correct font bolded so 🤷🏽‍♂️

Maybe I can create my own H1, H2, etc by wrapping Text and the proper variants?

Yeah, that’s because you set it to bold for h1 in your theme. You could indeed do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

H1, H2, H3, H4 Tags aren't rendering custom .ttf fonts in Android.
When specifying a custom True Type Font in tagStyles for h1, h2, h3 and/or h4, the font is not applied to the node...
Read more >
Custom font not working in React Native - Stack Overflow
In case somebody is reading this because their setup is fine and custom fonts work on iOS and in some cases don't work...
Read more >
Custom fonts not loading on mobile - Site Design & Styles
Hello, I uploaded a custom font and it's working fine on desktop but won't load on mobile. I've tested on both android and...
Read more >
font-family - CSS: Cascading Style Sheets - MDN Web Docs
The font-family CSS property specifies a prioritized list of one or more font family names and/or generic family names for the selected ...
Read more >
CSS @font-face in Browser and WebView does not work on ...
you must make sure the font on your android use default. because android get first font from local.
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