Repository navigation
Keep adjustsFontSizeToFit from shrinking text at whole-pixel heights on Android - #59792
Open
Abbondanzo wants to merge 2 commits into
Open
Abbondanzo wants to merge 2 commits into
Abbondanzo wants to merge 2 commits into
Conversation
Summary: A `Text` laid out at its own measured width is measured twice. This happens, for example, when it has `maxWidth: '100%'` inside a container that is only as wide as the text. The second measurement gets the first result back as its `AT_MOST` width, after Yoga adds and removes the container's padding and converts the width from pixels to DIPs and back, all in 32-bit floats. A whole number of pixels can come back a fraction short: at 420dpi, 372px comes back as 371.99997px. `TextLayoutManager.createLayout` floors `AT_MOST` widths, so the text gets a layout one pixel narrower than it was just measured to need and wraps onto a second line. Floor `AT_MOST` widths with a 0.001px tolerance, so a width that falls a float error short of a whole pixel keeps that pixel. Widths further below a whole pixel still round down. Adds a `createLayout` unit test and an RNTester example that lays out 17 labels at their own widths, each about a pixel wider than the last. Without this change, every label wraps at 320dpi and 6 of them wrap at 420dpi. Changelog: [Android][Fixed] - Fix `Text` wrapping onto a second line when it is laid out at its own measured width Differential Revision: D129505599
…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 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D129533186. |
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:
adjustsFontSizeToFitshrinks the font while the text layout is taller than itsAT_MOSTheight. 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 alineHeight, 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_MOSTheight with the same 0.001px tolerance the previous change added for widths, now namedPIXEL_SIZE_TOLERANCE.Adds a unit test and an RNTester example. The example lays out 17 labels, each with a
lineHeightof 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
adjustsFontSizeToFitshrinking text that exactly fits its container's heightDifferential Revision: D129533186