Skip to content

Keep adjustsFontSizeToFit from shrinking text at whole-pixel heights on Android - #59792

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
Abbondanzo:export-D129533186
Nov 11, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
Abbondanzo:export-D129533186

Conversation

@Abbondanzo

@Abbondanzo Abbondanzo commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:
adjustsFontSizeToFit shrinks the font while the text layout is taller than its AT_MOST height. That height arrives in pixels after Yoga subtracts the container's padding and converts it from DIPs back to pixels, all in 32-bit floats, so a whole number of pixels can come back a fraction short: 46px comes back as 45.999996px. A layout exactly as tall as the space it was given then counts as too tall. When the text sets a lineHeight, shrinking the font never makes it shorter, so it shrinks all the way to the minimum font size.

Compare the layout height against the AT_MOST height with the same 0.001px tolerance the previous change added for widths, now named PIXEL_SIZE_TOLERANCE.

Adds a unit test and an RNTester example. The example lays out 17 labels, each with a lineHeight of a whole number of pixels, in containers that leave exactly that height below their padding. Each row is a pixel taller than the last. Without this change, 11 of them shrink to the minimum font size at 320dpi and 4 at 420dpi.

Changelog:
[Android][Fixed] - Fix adjustsFontSizeToFit shrinking text that exactly fits its container's height

Differential Revision: D129533186

@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 D129533186.

@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
…on Android

Summary:
`adjustsFontSizeToFit` shrinks the font while the text layout is taller than its `AT_MOST` height. That height arrives in pixels after Yoga subtracts the container's padding and converts it from DIPs back to pixels, all in 32-bit floats, so a whole number of pixels can come back a fraction short: 46px comes back as 45.999996px. A layout exactly as tall as the space it was given then counts as too tall. When the text sets a `lineHeight`, shrinking the font never makes it shorter, so it shrinks all the way to the minimum font size.

Compare the layout height against the `AT_MOST` height with the same 0.001px tolerance the previous change added for widths, now named `PIXEL_SIZE_TOLERANCE`.

Adds a unit test and an RNTester example. The example lays out 17 labels, each with a `lineHeight` of a whole number of pixels, in containers that leave exactly that height below their padding. Each row is a pixel taller than the last. Without this change, 11 of them shrink to the minimum font size at 320dpi and 4 at 420dpi.

Changelog:
[Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text that exactly fits its container's height

Differential Revision: D129533186
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Nov 6, 2026
…on Android (react#59792)

Summary:

`adjustsFontSizeToFit` shrinks the font while the text layout is taller than its `AT_MOST` height. That height arrives in pixels after Yoga subtracts the container's padding and converts it from DIPs back to pixels, all in 32-bit floats, so a whole number of pixels can come back a fraction short: 46px comes back as 45.999996px. A layout exactly as tall as the space it was given then counts as too tall. When the text sets a `lineHeight`, shrinking the font never makes it shorter, so it shrinks all the way to the minimum font size.

Compare the layout height against the `AT_MOST` height with the same 0.001px tolerance the previous change added for widths, now named `PIXEL_SIZE_TOLERANCE`.

Adds a unit test and an RNTester example. The example lays out 17 labels, each with a `lineHeight` of a whole number of pixels, in containers that leave exactly that height below their padding. Each row is a pixel taller than the last. Without this change, 11 of them shrink to the minimum font size at 320dpi and 4 at 420dpi.

Changelog:
[Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text that exactly fits its container's height

Differential Revision: D129533186
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Nov 6, 2026
…on Android (react#59792)

Summary:
Pull Request resolved: react#59792

`adjustsFontSizeToFit` shrinks the font while the text layout is taller than its `AT_MOST` height. That height arrives in pixels after Yoga subtracts the container's padding and converts it from DIPs back to pixels, all in 32-bit floats, so a whole number of pixels can come back a fraction short: 46px comes back as 45.999996px. A layout exactly as tall as the space it was given then counts as too tall. When the text sets a `lineHeight`, shrinking the font never makes it shorter, so it shrinks all the way to the minimum font size.

Compare the layout height against the `AT_MOST` height with the same 0.001px tolerance the previous change added for widths, now named `PIXEL_SIZE_TOLERANCE`.

Adds a unit test and an RNTester example. The example lays out 17 labels, each with a `lineHeight` of a whole number of pixels, in containers that leave exactly that height below their padding. Each row is a pixel taller than the last. Without this change, 11 of them shrink to the minimum font size at 320dpi and 4 at 420dpi.

Changelog:
[Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text that exactly fits its container's height

Differential Revision: D129533186
@Abbondanzo
Abbondanzo requested a review from javache November 10, 2026 15:12

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
meta-codesync Bot merged commit 6b9afd8 into react:main Nov 11, 2026
89 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Abbondanzo in 6b9afd8

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 11, 2026
usama-liaqat pushed a commit to usama-liaqat/react-native that referenced this pull request Nov 14, 2026
…on Android

Summary:
`adjustsFontSizeToFit` shrinks the font while the text layout is taller than its `AT_MOST` height. That height arrives in pixels after Yoga subtracts the container's padding and converts it from DIPs back to pixels, all in 32-bit floats, so a whole number of pixels can come back a fraction short: 46px comes back as 45.999996px. A layout exactly as tall as the space it was given then counts as too tall. When the text sets a `lineHeight`, shrinking the font never makes it shorter, so it shrinks all the way to the minimum font size.

Compare the layout height against the `AT_MOST` height with the same 0.001px tolerance the previous change added for widths, now named `PIXEL_SIZE_TOLERANCE`.

Adds a unit test and an RNTester example. The example lays out 17 labels, each with a `lineHeight` of a whole number of pixels, in containers that leave exactly that height below their padding. Each row is a pixel taller than the last. Without this change, 11 of them shrink to the minimum font size at 320dpi and 4 at 420dpi.

Changelog:
[Android][Fixed] - Fix `adjustsFontSizeToFit` shrinking text that exactly fits its container's height

Differential Revision: D129533186

Pull Request resolved: react#59792
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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants