-
Notifications
You must be signed in to change notification settings - Fork 25k
[android][text] Fix text layout width calculation on Android 15 plus #54871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[android][text] Fix text layout width calculation on Android 15 plus #54871
Conversation
|
Thanks for mentioning me, @linhvovan29546 - appreciate it! Could you try to explain the fix in more detail, like what was wrong with the previous solution and why your solution fixes it? Then it is much more easy for us to review it! Thanks :) |
linhvovan29546
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrfalch I've added more details to the change rather than the PR description so we can discuss them in that thread. Could you take a look?
|
|
||
| val layoutWidth = | ||
| when (widthYogaMeasureMode) { | ||
| YogaMeasureMode.EXACTLY -> floor(width).toInt() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In https://github.com/facebook/react-native/pull/54721/changes#diff-8cc9a4af360b3eac066d7f9cd50d91da9cb6fc2fbf044b25d495666bcc95e2ebR662-R663 we changed Android 15+ to force layoutWidth to use AT_MOST. Since widthYogaMeasureMode may be EXACTLY, we need to handle that case otherwise the text will render incorrect as shown in the description. You can look the pre‑Android 15 logic.
| var desiredVisualWidth = 0f | ||
| for (i in 0 until unconstrainedLayout.lineCount) { | ||
| val lineWidth = unconstrainedLayout.getLineRight(i) - unconstrainedLayout.getLineLeft(i) | ||
| val lineWidth = unconstrainedLayout.getLineMax(i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change comes from the Expensify App( I tried to reproduce it in rn‑tester but couldn’t). When text has a lineHeight, the text rendered with width is too small, see the screenshot below where bottom‑navigation labels wrap and some text are truncated.
While debugging I found a suspicious calculation: the computed line width was too small, so I replaced the getLineRight/getLineLeft approach with getLineMax to compute the line width, which fixes the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes a lot of sense - I guess it wold be great adding two sections in the PR description for the meta reviewer telling what's wrong in the current version - and one on how to fix it - I won't be reviewing it internally - so this might be a great addition before we move on.
Thanks again, @linhvovan29546, for your contribution!
|
Thanks a lot! I’ve added two sections to the PR description. Please ask me for more details if anything is unclear. |
|
the best |
|
Hi @cortinico any update on this? |
I'll bring this up in my discussions with Riccardo. |
Summary:
After testing the patch from #54721, I noticed text-rendering issues in rn-tester on Android: some text is truncated and some lines do not wrap to the next line because the measured layout width calculation is inconsistent with how Android actually renders the text. This PR fixes two issues affecting text rendering on Android 15+
YogaMeasureMode.EXACTLYWhen thecreateLayoutspecifies an exact width constraint (EXACTLYmode), the current code falls through to the else and returnsceil(desiredVisualWidth)instead of respecting the exact width constraint. This causes the measured width to not match the container width, breaking layout calculation [android][text] Fix text layout width calculation on Android 15 plus #54871 (comment)rn‑tester. In the Expensify App, when text has a specificlineHeightthen the computed width is incorrect, which causes labels toclipor betruncated(see screenshot 2). While debugging I found theline-widthcalculation was wrong, then i replacing thegetLineRight/getLineLeftapproach withgetLineMaxfor computing line width resolves the issue. [android][text] Fix text layout width calculation on Android 15 plus #54871 (comment)Changelog:
[ANDROID] [FIXED] - Fix text layout calculation on Android 15+
Test Plan:
Tests
Results:
Screen.Recording.2025-12-12.at.21.34.50.mov