From ed4a4d80b7c8364b85dee04d00e3c51873d72e6a Mon Sep 17 00:00:00 2001 From: dexical30 Date: Sat, 28 Mar 2026 18:34:18 +0900 Subject: [PATCH] Fix onTextLayout reporting incorrect lines in EXACTLY width mode on Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `measureLines()` passes `YogaMeasureMode.EXACTLY` to `createLayout()`. In the pre-Android 15 path, `EXACTLY` mode used `floor(width)` to compute the StaticLayout width, which could produce a layout that is 1px narrower than the width allocated by Yoga. This causes single-line text (e.g. "Welcome!") to be reported as multiple lines in `onTextLayout` when placed next to a `flexGrow: 1` sibling — even though the text visually renders on one line. Changing `floor` to `ceil` ensures the StaticLayout has at least enough space to match what the TextView actually renders. Fixes: https://github.com/facebook/react-native/issues/54552 --- .../java/com/facebook/react/views/text/TextLayoutManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt index f2c88294f65..28b73a3da82 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt @@ -637,7 +637,7 @@ internal object TextLayoutManager { val layoutWidth = when (widthYogaMeasureMode) { - YogaMeasureMode.EXACTLY -> floor(width).toInt() + YogaMeasureMode.EXACTLY -> ceil(width).toInt() YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt()) else -> desiredWidth }