-
Notifications
You must be signed in to change notification settings - Fork 24.6k
Adjust iOS line height calculation #44679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Base commit: 8b53d41 |
hello @cipolleschi , could you help to review the adjustment? |
5f653ee
to
90b116a
Compare
|
||
// Calculate baseline offset based on font size and maximum available line height value | ||
CGFloat maximumLineHeight = MAX(paragraphLineHeight, fontLineHeight); | ||
CGFloat baselineOffset = (fontSize - maximumLineHeight) / 1.5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why we were using 2.0 before and now we are using 1.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, its quite a "magic" number that can give big enough space to cater text with accent 🤞
This might be impacting normal text to have bigger white space than before, depends on the font's pointSize
and lineHeight
comparison
The code looks good. However, it is always a bit problematic to work with these changes as text is a delicate beast and we could introduce regressions and test failures. I'll try to import it, but to set expectations, we might not be able to merge this. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi! A colleague pointed out that this PR only address the Old Architecture.
Thank you so much! |
hi @cipolleschi! I haven't tried it on New Arch yet, mostly working with Old Arch. I will check if this issue also happens on the New Arch. |
hi @cipolleschi, just checked that it also happens in the New Arch, already updated the changes to handle Text on New Arch |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@adrianha Hi, thank you for fixing this issue 🙏 I'm also using a custom Korean font Pretendard in react-native 0.73.8 (old architecture), I am experiencing an issue where the baseline of the text rises when emojis are included in the text. |
I was discussing this fix with @NickGerleman internally and we realized that this fix breaks several tests internally and it breaks vertical centering of Text. I really understand having some fonts cut off is an issue, but we have to look for alternative solutions, different from this one. Unfortunately I don't have good suggestions for where to look, at the moment. |
hi @floydkim, I'm not able to check it atm. Anyway, you can try to apply the changes directly on node_modules and rebuild the iOS app, it should pick up the update. Let me know if this works for your case |
hi @cipolleschi, totally understandable, this issue is quite tricky. Could you add more details regarding vertical centering of Text issue? Do you think we also need to adjust that mechanism as well? |
I tried it. This diff lowers the baseline of all text regardless of whether a custom font is applied.
|
Summary:
This diff will adjust line height calculation for
Text
andTextInput
on iOS which is needed to fix cropped text in some fonts that have higher accent, e.g. Vietnam.Line height calculation will use
fontSize
as the anchor to define the text offset.On Android, it seems fine, text not cropped, attached on the
Test Plan
section.Changelog:
Test Plan:
It was tested using Be Vietnam Pro font to render
CHỖ
text. Before the adjustment, the text will be cropped as it needs higher line height.Before
After
Android