Line height is distributed unevenly when lineHeight <= fontSize
See original GitHub issueDescription
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.
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:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:12 (3 by maintainers)
Top GitHub Comments
I can confirm that this is still an issue
Thanks for the tip with the workaround @andymatuschak
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. viatop
plus relative positioning, or a negativemarginTop
).