fix(android): Prevent text cut-off by clamping lineHeight to font height#56864
Open
aswinandro wants to merge 1 commit into
Open
fix(android): Prevent text cut-off by clamping lineHeight to font height#56864aswinandro wants to merge 1 commit into
aswinandro wants to merge 1 commit into
Conversation
On Android 15 & 16, text was being cut off when lineHeight was set smaller than the font’s ascent + descent, due to changes in the platform’s text rendering. This patch updates CustomLineHeightSpan to always ensure the line box is at least as large as the font’s required height, and sets fm.top/fm.bottom to match the adjusted ascent/descent for all lines. This prevents descenders and ascenders from being clipped, matching native TextView and web behavior, and does not affect other text features or layouts. Fixes facebook#56402, facebook#53286.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Android 15 & 16, text was being cut off when
lineHeightwas set smaller than the font’s ascent + descent, due to changes in the platform’s text rendering.This patch updates
CustomLineHeightSpanto always ensure the line box is at least as large as the font’s required height, and setsfm.top/fm.bottomto match the adjusted ascent/descent for all lines.This prevents descenders and ascenders from being clipped, matching native TextView and web behavior, and does not affect other text features or layouts.
Fixes #56402, #53286, #56402
Changelog:
[Android] [Fixed] - Prevent text cut-off when
lineHeightis less than font size by clamping line height to font metrics inCustomLineHeightSpan. This ensures text is never clipped on Android 15 & 16 and matches native TextView/web behavior. Fixes #56402, #53286, 56402For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
Test Plan
fontSizeandlineHeight, including cases wherelineHeight < fontSize.Example test code: