Repository navigation
Keep line heights from making adjustsFontSizeToFit shrink text on Android (#59800) - #59800
Open
Abbondanzo wants to merge 1 commit into
Open
Abbondanzo wants to merge 1 commit into
Abbondanzo wants to merge 1 commit into
Conversation
|
@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D129646293. |
Abbondanzo
force-pushed
the
export-D129646293
branch
from
November 6, 2026 22:29
92ab495 to
0997196
Compare
Abbondanzo
added a commit
to Abbondanzo/react-native
that referenced
this pull request
Nov 6, 2026
…roid (react#59800) Summary: Pull Request resolved: react#59800 Android lays text out in lines a whole number of pixels tall, so `CustomLineHeightSpan` rounds a `lineHeight` up to the next whole pixel. That broke `adjustsFontSizeToFit` for text whose lines exactly fill its container: - A `lineHeight` that isn't a whole number of pixels, such as 20dp at 420dpi (52.5px), is laid out as 53px, which doesn't fit the 52.5px its container leaves for it. - A `lineHeight` that converts to a hair over a whole number of pixels, such as 44.000004px, is laid out a whole pixel taller than it asks for. `adjustsFontSizeToFit` then shrinks the font. Shrinking it never makes a line with a fixed `lineHeight` shorter, so the text drops to the minimum font size, and text with `numberOfLines` greater than 1 collapses onto fewer lines. - `CustomLineHeightSpan` no longer rounds a line height up past a whole number of pixels it only exceeds by floating point error, using the tolerance `PIXEL_SIZE_TOLERANCE` that the earlier changes added. - `adjustsFontSizeToFit` compares the available height with the layout's height minus what rounding its line heights added, so text fits when its line heights, as given, fit. Text without a `lineHeight` is compared as before. Adds unit tests and an RNTester example with nine one-line and nine two-line labels whose lines exactly fill their containers. Each label's line height is half a pixel taller than the last. Without this change, 10 of the 18 labels shrink at 420dpi and 8 at 320dpi. Changelog: [Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text whose `lineHeight` exactly fills its container Differential Revision: D129646293
Abbondanzo
force-pushed
the
export-D129646293
branch
from
November 6, 2026 22:33
0997196 to
5402f54
Compare
…roid (react#59800) Summary: Pull Request resolved: react#59800 Android lays text out in lines a whole number of pixels tall, so `CustomLineHeightSpan` rounds a `lineHeight` up to the next whole pixel. That broke `adjustsFontSizeToFit` for text whose lines exactly fill its container: - A `lineHeight` that isn't a whole number of pixels, such as 20dp at 420dpi (52.5px), is laid out as 53px, which doesn't fit the 52.5px its container leaves for it. - A `lineHeight` that converts to a hair over a whole number of pixels, such as 44.000004px, is laid out a whole pixel taller than it asks for. `adjustsFontSizeToFit` then shrinks the font. Shrinking it never makes a line with a fixed `lineHeight` shorter, so the text drops to the minimum font size, and text with `numberOfLines` greater than 1 collapses onto fewer lines. - `CustomLineHeightSpan` no longer rounds a line height up past a whole number of pixels it only exceeds by floating point error, using the tolerance `PIXEL_SIZE_TOLERANCE` that the earlier changes added. - `adjustsFontSizeToFit` compares the available height with the layout's height minus what rounding its line heights added, so text fits when its line heights, as given, fit. Text without a `lineHeight` is compared as before. Adds unit tests and an RNTester example with nine one-line and nine two-line labels whose lines exactly fill their containers. Each label's line height is half a pixel taller than the last. Without this change, 10 of the 18 labels shrink at 420dpi and 8 at 320dpi. Changelog: [Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text whose `lineHeight` exactly fills its container Differential Revision: D129646293
Abbondanzo
force-pushed
the
export-D129646293
branch
from
November 11, 2026 18:15
5402f54 to
5a36284
Compare
This branch has not been deployed
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:
Android lays text out in lines a whole number of pixels tall, so
CustomLineHeightSpanrounds alineHeightup to the next whole pixel. That brokeadjustsFontSizeToFitfor text whose lines exactly fill its container:lineHeightthat isn't a whole number of pixels, such as 20dp at 420dpi (52.5px), is laid out as 53px, which doesn't fit the 52.5px its container leaves for it.lineHeightthat converts to a hair over a whole number of pixels, such as 44.000004px, is laid out a whole pixel taller than it asks for.adjustsFontSizeToFitthen shrinks the font. Shrinking it never makes a line with a fixedlineHeightshorter, so the text drops to the minimum font size, and text withnumberOfLinesgreater than 1 collapses onto fewer lines.CustomLineHeightSpanno longer rounds a line height up past a whole number of pixels it only exceeds by floating point error, using the tolerancePIXEL_SIZE_TOLERANCEthat the earlier changes added.adjustsFontSizeToFitcompares the available height with the layout's height minus what rounding its line heights added, so text fits when its line heights, as given, fit. Text without alineHeightis compared as before.Adds unit tests and an RNTester example with nine one-line and nine two-line labels whose lines exactly fill their containers. Each label's line height is half a pixel taller than the last. Without this change, 10 of the 18 labels shrink at 420dpi and 8 at 320dpi.
Changelog:
[Android][Fixed] - Fix
adjustsFontSizeToFitshrinking text whoselineHeightexactly fills its containerDifferential Revision: D129646293