Skip to content

Include fallback line spacing in BoringLayout Metrics#51304

Closed
NickGerleman wants to merge 3 commits into
facebook:mainfrom
NickGerleman:export-D74694483
Closed

Include fallback line spacing in BoringLayout Metrics#51304
NickGerleman wants to merge 3 commits into
facebook:mainfrom
NickGerleman:export-D74694483

Conversation

@NickGerleman
Copy link
Copy Markdown
Contributor

Summary:
A potential source of truncation we previously experienced with D65171352 is difference in how TextView calculates line spacing with StaticLayout.

As of Android 13, this also appies to how TextView creates the metrics of BoringLayout. Oddly, this is not also applied to BoringLayout.make() (I think it ends up only impacting metrics), so we don't pass the flag there. See https://cs.android.com/android/_/android/platform/frameworks/base/+/78c774defb238c05c42b34a12b6b3b0c64844ed7

This could cause some theoretical truncation of simple single line text, so let's match TextView expectations.

Changelog:
[Android][Fixed] - Include fallback line spacing in BoringLayout

Differential Revision: D74694483

Summary:
X-link: facebook/yoga#1811


## Resubmit

This was backed out due to being up the stack from another change that was backed out, but should be safe by itself.

## Original

We want to know if an artifact created during measurement can fully be reused after final layout, but the final layout is allowed to be slightly larger due to pixel grid rounding (while still allowing reuse). It's hard to tell after the fact, whether it is larger because of this rounding (though the measure is used), or if it may be a pixel larger for valid reasons.

We can expose the unsnapped dimensions of a node to give us this information, and to correlate measurement artifacts.

This is most of the time the same as the layout's measured dimension, though I don't think it's safe to use this, since anything else measuring the node after could clobber this (I think `YGNodeLayoutGetOverflow` may also be prone to this as a bug).

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D74673119
Summary:

We do a lot of incorrect `cei()` in text measurement, compensated later by other incorrect bits.

There are a couple of interesting bits here:

A "desired width" is how large a hypothetical text layout would like to be. It is a floating point value, and to avoid truncation, a container must be larger than the desired width. So ceiling this is correct.

We are also passed available width, which may be an exact specification, not at a subpixel boundary. Ceiling this is totally incorrect, since Yoga will disregard our ceiled version, and we just created a layout, larger than our actual measure will be.

We must instead floor `availableWidth`, and we create our layout based off of that, to not give an extra physical pixel, that may not be given to us, if later layout rounding doesn't go our way. We then ceil `desiredWidth` earlier.

Finally, when we have an exact measuremode, we create the layout so that it uses guaranteedWidth`, but act as if it takes the full available space, per-contract, which may be a subpixel size larger. This means we cannot create layouts which cause truncation.

I used this change as an opportunity to clean up `createLayout()`, since we are gating anyways, to remove the duplicated paths, and to avoid the unnecessary `TextDirectionHeuristic` work for BoringLayout case, and since `StaticLayoutBuilder` already defaults to the heuristic we are manually setting.

Changelog:
[Android][Fixed] - Fix more text rounding bugs

Reviewed By: joevilches

Differential Revision: D74685353
Summary:
A potential source of truncation we previously experienced with D65171352 is difference in how TextView calculates line spacing with StaticLayout.

As of Android 13, this also appies to how TextView creates the metrics of BoringLayout. Oddly, this is not also applied to `BoringLayout.make()` (I think it ends up only impacting metrics), so we don't pass the flag there. See https://cs.android.com/android/_/android/platform/frameworks/base/+/78c774defb238c05c42b34a12b6b3b0c64844ed7

This could cause some theoretical truncation of simple single line text, so let's match TextView expectations.

Changelog:
[Android][Fixed] - Include fallback line spacing in BoringLayout

Differential Revision: D74694483
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels May 14, 2025
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74694483

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 2fe6c1a.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @NickGerleman in 2fe6c1a

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

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. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants