Repository navigation
Conversation
…dths createLayout() wrapped text at floor(width) for AT_MOST but at ceil(width) for EXACTLY. Text whose width falls in (floor(width), width] was measured with one more line than it was drawn with, which left an empty line below it. AT_MOST now wraps at ceil(width), like EXACTLY. calculateWidth() clamps the reported width to the AT_MOST width, so the size returned to Yoga still never exceeds the constraint. Fixes react#59174 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @hcbylmz! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Closing: on-device testing showed this change breaks |
Summary:
Fixes #59174.
On Android,
TextLayoutManager.createLayout()wraps text atfloor(width)when Yoga measures withAT_MOST, but atceil(width)when the text is drawn withEXACTLY. When the text width falls in(floor(width), width], measuring wraps it to one more line than drawing does. The view keeps the taller measured height, so an empty line shows below the text. The issue has a real case: a 467.17 px text in a 467.99997 px column (density 2.1).#56651 changed
EXACTLYtoceiland keptAT_MOSTonfloor, so the reported size never goes over theAT_MOSTconstraint. This PR keeps that rule and changes where the text wraps:AT_MOSTnow wraps atceil(width), the same widthEXACTLYuses, so measure and draw break lines the same way.calculateWidth()returnsmin(layout.width, width)forAT_MOST, so the width reported to Yoga still never goes over the constraint. The layout can be up to a subpixel wider thanwidth. Drawing already does the same withceil(width).The issue suggests
floor(width + 0.01f). That fixes float rounding cases like 467.99997, but not real fractional widths like 467.5, where the same mismatch happens. The new test uses such a width.Thanks to @YigitGok for the root cause analysis in the issue.
Changelog:
[ANDROID] [FIXED] - Fix
Textmeasured one line taller than it is drawn when its width is a fractional pixel valueTest Plan:
Added
TextLayoutManagerAtMostFractionalWidthTest(Robolectric,GraphicsMode.NATIVEso text is measured with real fonts). It builds the layout for the same fractional width withAT_MOSTand withEXACTLYand checks that both have the same line count.AT_MOSTgives 2 lines (layout width 163) andEXACTLYgives 1 line (layout width 164).All 765 ReactAndroid unit tests pass, including
TextLayoutManagerAbsoluteLayoutWithFractionalPixelTestfrom #56651.🤖 Generated with Claude Code