Skip to content

Keep line heights from making adjustsFontSizeToFit shrink text on Android (#59800) - #59800

Open
Abbondanzo wants to merge 1 commit into
react:mainfrom
Abbondanzo:export-D129646293
Open

Abbondanzo wants to merge 1 commit into
react:mainfrom
Abbondanzo:export-D129646293

Conversation

@Abbondanzo

@Abbondanzo Abbondanzo commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

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

@meta-codesync

meta-codesync Bot commented Nov 4, 2026

Copy link
Copy Markdown

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D129646293.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 4, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Nov 4, 2026
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
@meta-codesync meta-codesync Bot changed the title Keep line heights from making adjustsFontSizeToFit shrink text on Android Keep line heights from making adjustsFontSizeToFit shrink text on Android (#59800) 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant