Open andymatuschak opened 4 years ago
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
).
Does adding this prop help textAlignVertical='center'
?
@ravirajn22: Nope, that doesn't change the output, neither on Android nor on iOS.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
Nope, the issue has not been fixed; it still requires attention. I don't seem to have permission to add it to the backlog.
I can confirm that this is still an issue
Thanks for the tip with the workaround @andymatuschak
Yep, still an issue
Still an issue
Agreed, still an issue, bot.
On Windows, XAML has LineStackingStrategy and TextLineBounds for fine-tuning the text positioning. On web, there's a proposal for "leading-trim".
Do iOS or Android have anything similar that could be used or exposed?
Still an issue
Same issue here. Basically, any characters that were not part of the font package were causing this issue for me.
Definitely still an issue and the workaround is not great if you ever have Text within Text, they no longer align when they both have some kind of top offset
Would be great to bring some attention to this issue. The workaround mentioned in #7687 is hacky and will not work properly with special capital characters (e.g. Å, Á, È) unless you manually tweak paddings to "just about right".
try just verticalAlign:"bottom" or verticalAlign:"bottom" lineHeight:1, height: 24 => here you define the height you want for your text
Still an issue
it is caused by the baseline of the Text. The Text and TextInput implementations are similar, you can find relevant explanations of how baseline is set on react native in this prs https://github.com/facebook/react-native/pull/38359 https://github.com/facebook/react-native/pull/37465. I'll follow up
Still an issue
Still an issue
Hey @fabOnReact, it seems like you have the best understanding of this bug. Certain fonts have different ascents/descents and iOS doesn't adjust the baseline based on this difference. This presents unnoticeably on many fonts, but for some other fonts the difference can be drastic.
The fix you linked to involves the TextInput
component. Do you know if there's a similar fix for Text
? I'm seeing the incorrect line height issue on both.
It is also a problem when using special characters even if the lineHeight > fontSize as they get cut off. The hacky padding workaround works but is not ideal https://github.com/facebook/react-native/issues/29507#issuecomment-1529425022
Here is lineHeight: 37
and fontSize: 32
Android
Web
This is crazy, just to follow up it
fyi: we've added a fix for this here: https://github.com/facebook/react-native/pull/46362, although we are still testing before rollout
Closing as the PR mentioned by @mellyeliu has been merged and will be shipped with React Native 0.76
@mellyeliu @cortinico The issue seems to affect both Android and iOS and the PR only introduces a solution for Android. Can we reopen until iOS is also addressed?
Reopening until iOS fix for tracking purposes
Description
When
lineHeight
is less than thefontSize
,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 whenlineHeight
is less thanfontSize
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:
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