From 18b0f82b85be6d05b7c30f938d0437fc596ccd52 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 30 Oct 2026 15:12:25 +0000 Subject: [PATCH] fix(mobile): Android composer no longer flips between rows at the wrap boundary The Android editor truncated a one-line draft's natural width to whole pixels before reporting it. A line slightly wider than the compact slot then reported a width equal to the slot, so JS collapsed the composer, the line wrapped, and the composer expanded again. Round the width up so a reported width that fits the slot means the line fits it too. Co-Authored-By: Claude Opus 5.5 --- .../t3composereditor/T3ComposerEditorView.kt | 9 +++- .../ComposerContentWidthTest.kt | 49 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerContentWidthTest.kt diff --git a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt index ecc37df17c993..22e0f47064db6 100644 --- a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt +++ b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt @@ -11,6 +11,7 @@ import android.os.Build import android.text.Editable import android.text.InputType import android.text.InputFilter +import android.text.Layout import android.text.Spanned import android.text.TextUtils import android.text.TextWatcher @@ -30,6 +31,7 @@ import expo.modules.kotlin.AppContext import expo.modules.kotlin.viewevent.EventDispatcher import expo.modules.kotlin.views.ExpoView import org.json.JSONObject +import kotlin.math.ceil import kotlin.math.max class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( @@ -433,7 +435,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( // wrapping it, so getLineMax leaves it out. val layout = editor.layout val contentHeight = layout?.height ?: editor.measuredHeight - val contentWidth = if (layout?.lineCount == 1) layout.getLineMax(0).toInt() else 0 + val contentWidth = singleLineContentWidth(layout) if (contentHeight == lastContentHeight && contentWidth == lastContentWidth) return lastContentHeight = contentHeight lastContentWidth = contentWidth @@ -495,6 +497,11 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( } } +// Round up: a truncated width can match a slot the line overflows, and the composer +// then flips between its compact and expanded rows. +internal fun singleLineContentWidth(layout: Layout?): Int = + if (layout?.lineCount == 1) ceil(layout.getLineMax(0)).toInt() else 0 + private fun Int.withAlpha(alpha: Int): Int = (this and 0x00FFFFFF) or (alpha shl 24) private fun Context.resolveThemeColor(attribute: Int, fallback: Int): Int { diff --git a/apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerContentWidthTest.kt b/apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerContentWidthTest.kt new file mode 100644 index 0000000000000..458ad4e007d1b --- /dev/null +++ b/apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerContentWidthTest.kt @@ -0,0 +1,49 @@ +package expo.modules.t3composereditor + +import android.text.Layout +import android.view.View +import android.view.ViewGroup +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode +import kotlin.math.floor + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [36], manifest = Config.NONE) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class ComposerContentWidthTest { + private val editor = SelectionAwareEditText(RuntimeEnvironment.getApplication()).apply { + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + ) + textSize = 16f + setPadding(0, 0, 0, 0) + } + + private fun layoutAt(width: Int): Layout { + editor.measure( + View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + ) + editor.layout(0, 0, width, editor.measuredHeight) + return editor.layout + } + + // JS keeps the compact row when the reported width is at most the compact slot's. + @Test + fun reportedWidthStillFitsOnOneLine() { + editor.setText("I know t3 code exposes a websocket") + val wide = layoutAt(10_000) + val natural = wide.getLineMax(0) + assertNotEquals("the draft needs a fractional width", floor(natural), natural) + + val reported = singleLineContentWidth(wide) + assertEquals(1, layoutAt(reported).lineCount) + } +}