From 8b00b4f2860de50e5cefa43735d32bf4bdb8518d Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Mon, 28 Nov 2022 15:57:37 -0800 Subject: [PATCH] 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 --- .../com/facebook/react/views/text/TextLayoutManager.java | 7 +++++++ .../react/views/text/TextLayoutManagerMapBuffer.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 964152d93df..870545bc5f4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -407,6 +407,13 @@ public class TextLayoutManager { } } + // Android 11+ introduces changes in text width calculation which leads to cases + // where the container is measured smaller than text. Math.ceil prevents it + // See T136756103 for investigation + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) { + calculatedWidth = (float) Math.ceil(calculatedWidth); + } + float calculatedHeight = height; if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) { calculatedHeight = layout.getLineBottom(calculatedLineCount - 1); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java index e2a8c05f2f0..9ff17c4359f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java @@ -427,6 +427,13 @@ public class TextLayoutManagerMapBuffer { } } + // Android 11+ introduces changes in text width calculation which leads to cases + // where the container is measured smaller than text. Math.ceil prevents it + // See T136756103 for investigation + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) { + calculatedWidth = (float) Math.ceil(calculatedWidth); + } + float calculatedHeight = height; if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) { calculatedHeight = layout.getLineBottom(calculatedLineCount - 1);