-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -666,12 +666,13 @@ internal object TextLayoutManager { | |
| // Calculate visual bounds width from unconstrained layout | ||
| var desiredVisualWidth = 0f | ||
| for (i in 0 until unconstrainedLayout.lineCount) { | ||
| val lineWidth = unconstrainedLayout.getLineRight(i) - unconstrainedLayout.getLineLeft(i) | ||
| val lineWidth = unconstrainedLayout.getLineMax(i) | ||
| desiredVisualWidth = max(desiredVisualWidth, lineWidth) | ||
| } | ||
|
|
||
| val layoutWidth = | ||
| when (widthYogaMeasureMode) { | ||
| YogaMeasureMode.EXACTLY -> floor(width).toInt() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| YogaMeasureMode.AT_MOST -> min(ceil(desiredVisualWidth).toInt(), floor(width).toInt()) | ||
| else -> ceil(desiredVisualWidth).toInt() | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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/getLineLeftapproach withgetLineMaxto compute the line width, which fixes the problemThere 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!