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.

Line height is distributed unevenly when lineHeight <= fontSize

See original GitHub issue

Description

When lineHeight is less than the fontSize, Text shrinks the line’s bounding box only by removing space from above the text, rather than distributing the space evenly above and below, as is done with extra line height. Actually, the issue manifests when lineHeight is less than fontSize plus some small amount (perhaps the font bounding box height?)—e.g. <= 45px for 40px Helvetica.

This leads to clipped glyphs and produces differences in text rendering between react-native-web and react-native (https://github.com/necolas/react-native-web/issues/1687). After some discussion with @necolas, my inclination is that RNW’s behavior is the more reasonable one, so I thought I’d open an issue here.

This issue reproduces across a variety of fonts.

image

Unfortunately,I worry that fixing this issue will create subtle and surprising source compatibility issues for existing clients.

React Native version:

System:
    OS: macOS 10.15.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 337.02 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.21.0 - ~/.nvm/versions/node/v10.21.0/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v10.21.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.2 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: 0.63.2 => 0.63.2 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Run example app here: https://snack.expo.io/W51F2OAqD

Expected Results

The extra line spacing should be removed evenly from both above and below the type.

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/W51F2OAqD

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Dinkelborgcommented, Apr 21, 2021

I can confirm that this is still an issue

Thanks for the tip with the workaround @andymatuschak

3reactions
andymatuschakcommented, Jul 28, 2020

A workaround for readers who stumble on this issue: if you’d like to use smaller line heights without glyph clipping, you’ll need to add top padding to the Text element, which you must then compensate for by shifting the element up (e.g. via top plus relative positioning, or a negative marginTop).

Read more comments on GitHub >

github_iconTop Results From Across the Web

line-height is uneven. Larger space above text than under
That space belongs to the characters themselves; Which means you have to edit the font via a Font editor application to align the...
Read more >
line-height - CSS: Cascading Style Sheets - MDN Web Docs
The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text.
Read more >
Typography sizing and line height in web design - YouTube
In this video we look at how to quickly set up our typography in Figma for a very easy and efficient workflow in...
Read more >
Line-Height - Cascading Style Sheets Properties
This property specifies the height of an in-line element box. If the 'line-height' value is greater than the value of the 'font-size' for...
Read more >
Change line spacing
Your text is now distributed evenly inside the cell. If you change the height of the row, the text re-adjusts evenly to the...
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