Skip to content

Commit 8b00b4f

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
Text measurement, Math.ceil calculatedWidth
Summary: Changelog: [Internal] - Fix incorrect text container measurement for Android 11+ Reviewed By: mdvacca Differential Revision: D41559873 fbshipit-source-id: 76c200693cd10b9b7fe883dd81b0c3c1dbdecf27
1 parent 6c33fd1 commit 8b00b4f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ public static long measureText(
407407
}
408408
}
409409

410+
// Android 11+ introduces changes in text width calculation which leads to cases
411+
// where the container is measured smaller than text. Math.ceil prevents it
412+
// See T136756103 for investigation
413+
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) {
414+
calculatedWidth = (float) Math.ceil(calculatedWidth);
415+
}
416+
410417
float calculatedHeight = height;
411418
if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) {
412419
calculatedHeight = layout.getLineBottom(calculatedLineCount - 1);

ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ public static long measureText(
427427
}
428428
}
429429

430+
// Android 11+ introduces changes in text width calculation which leads to cases
431+
// where the container is measured smaller than text. Math.ceil prevents it
432+
// See T136756103 for investigation
433+
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) {
434+
calculatedWidth = (float) Math.ceil(calculatedWidth);
435+
}
436+
430437
float calculatedHeight = height;
431438
if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) {
432439
calculatedHeight = layout.getLineBottom(calculatedLineCount - 1);

0 commit comments

Comments
 (0)