@devries-cameron20 / t3code-1 / commits / 16f1d0a239
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): stop Android composer flicker at the wrap boundary (#27682)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

shivam committed Nov 6, 2026 at 06:18 UTC 16f1d0a239f8840a5a348556124a3ef3c8f11e88
2 files changed +57 -1
apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
+8 -1
@@ -12,6 +12,7 @@ import android.os.Build
12 import android.text.Editable
13 import android.text.InputType
14 import android.text.InputFilter
15 +import android.text.Layout
16 import android.text.Spanned
17 import android.text.TextUtils
18 import android.text.TextWatcher
@@ -32,6 +33,7 @@ import expo.modules.kotlin.AppContext
33 import expo.modules.kotlin.viewevent.EventDispatcher
34 import expo.modules.kotlin.views.ExpoView
35 import org.json.JSONObject
36 +import kotlin.math.ceil
37 import kotlin.math.max
38
39 class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
@@ -435,7 +437,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
437 // wrapping it, so getLineMax leaves it out.
438 val layout = editor.layout
439 val contentHeight = layout?.height ?: editor.measuredHeight
438 - val contentWidth = if (layout?.lineCount == 1) layout.getLineMax(0).toInt() else 0
440 + val contentWidth = singleLineContentWidth(layout)
441 if (contentHeight == lastContentHeight && contentWidth == lastContentWidth) return
442 lastContentHeight = contentHeight
443 lastContentWidth = contentWidth
@@ -497,6 +499,11 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
499 }
500 }
501
502 +// Round up: a truncated width can match a slot the line overflows, and the composer
503 +// then flips between its compact and expanded rows.
504 +internal fun singleLineContentWidth(layout: Layout?): Int =
505 + if (layout?.lineCount == 1) ceil(layout.getLineMax(0)).toInt() else 0
506 +
507 private fun Int.withAlpha(alpha: Int): Int = (this and 0x00FFFFFF) or (alpha shl 24)
508
509 private fun Context.resolveThemeColor(attribute: Int, fallback: Int): Int {
apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerContentWidthTest.kt new
+49
@@ -0,0 +1,49 @@
1 +package expo.modules.t3composereditor
2 +
3 +import android.text.Layout
4 +import android.view.View
5 +import android.view.ViewGroup
6 +import org.junit.Assert.assertEquals
7 +import org.junit.Assert.assertNotEquals
8 +import org.junit.Test
9 +import org.junit.runner.RunWith
10 +import org.robolectric.RobolectricTestRunner
11 +import org.robolectric.RuntimeEnvironment
12 +import org.robolectric.annotation.Config
13 +import org.robolectric.annotation.GraphicsMode
14 +import kotlin.math.floor
15 +
16 +@RunWith(RobolectricTestRunner::class)
17 +@Config(sdk = [36], manifest = Config.NONE)
18 +@GraphicsMode(GraphicsMode.Mode.NATIVE)
19 +class ComposerContentWidthTest {
20 + private val editor = SelectionAwareEditText(RuntimeEnvironment.getApplication()).apply {
21 + layoutParams = ViewGroup.LayoutParams(
22 + ViewGroup.LayoutParams.MATCH_PARENT,
23 + ViewGroup.LayoutParams.WRAP_CONTENT,
24 + )
25 + textSize = 16f
26 + setPadding(0, 0, 0, 0)
27 + }
28 +
29 + private fun layoutAt(width: Int): Layout {
30 + editor.measure(
31 + View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
32 + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
33 + )
34 + editor.layout(0, 0, width, editor.measuredHeight)
35 + return editor.layout
36 + }
37 +
38 + // JS keeps the compact row when the reported width is at most the compact slot's.
39 + @Test
40 + fun reportedWidthStillFitsOnOneLine() {
41 + editor.setText("I know t3 code exposes a websocket")
42 + val wide = layoutAt(10_000)
43 + val natural = wide.getLineMax(0)
44 + assertNotEquals("the draft needs a fractional width", floor(natural), natural)
45 +
46 + val reported = singleLineContentWidth(wide)
47 + assertEquals(1, layoutAt(reported).lineCount)
48 + }
49 +}