The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): hardware Enter keeps the Android terminal focused (#24928)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 31, 2026 at 03:44 UTC
19a773f893a522e61f6b2d619c052386b5811457
4 files changed
+89
-13
apps/mobile/modules/t3-terminal/android/build.gradle
+12
@@ -9,6 +9,10 @@ android {
9
ndkVersion rootProject.ext.ndkVersion
10
compileSdk rootProject.ext.compileSdkVersion
11
12
+ testOptions {
13
+ unitTests.includeAndroidResources = true
14
+ }
15
+
16
defaultConfig {
17
minSdkVersion rootProject.ext.minSdkVersion
18
targetSdkVersion rootProject.ext.targetSdkVersion
@@ -37,4 +41,12 @@ android {
41
42
dependencies {
43
implementation project(':expo-modules-core')
44
+ testImplementation 'junit:junit:4.13.2'
45
+ testImplementation 'org.robolectric:robolectric:4.16.1'
46
+}
47
+
48
+tasks.withType(Test).configureEach {
49
+ javaLauncher = javaToolchains.launcherFor {
50
+ languageVersion = JavaLanguageVersion.of(21)
51
+ }
52
}
apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt
+4
-13
@@ -271,21 +271,12 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
271
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD or
272
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
273
inputView.setPadding(0, 0, 0, 0)
274
- inputView.setOnEditorActionListener { _, actionId, event ->
275
- if (readOnly) return@setOnEditorActionListener true
276
- val isKeyUp = event?.action == KeyEvent.ACTION_UP
277
- val isImeSend = actionId == EditorInfo.IME_ACTION_SEND && !isKeyUp
278
- val isHardwareEnter = event?.keyCode == KeyEvent.KEYCODE_ENTER &&
279
- event.action == KeyEvent.ACTION_DOWN
280
- val isEnter = isImeSend || isHardwareEnter
281
- if (isEnter) {
274
+ inputView.setOnEditorActionListener(
275
+ TerminalEnterListener({ readOnly }) {
276
// Enter must send CR: raw-mode TUIs treat LF as Ctrl+J (insert newline).
277
onInput(mapOf("data" to "\r"))
284
- true
285
- } else {
286
- false
287
- }
288
- }
278
+ },
279
+ )
280
inputView.setOnKeyListener { _, keyCode, event ->
281
if (readOnly) return@setOnKeyListener true
282
if (event.action != KeyEvent.ACTION_DOWN) return@setOnKeyListener false
apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/TerminalEnterListener.kt
new
+22
@@ -0,0 +1,22 @@
1
+package expo.modules.t3terminal
2
+
3
+import android.view.KeyEvent
4
+import android.view.inputmethod.EditorInfo
5
+import android.widget.TextView
6
+
7
+internal class TerminalEnterListener(
8
+ private val isReadOnly: () -> Boolean,
9
+ private val sendEnter: () -> Unit
10
+) : TextView.OnEditorActionListener {
11
+ override fun onEditorAction(view: TextView?, actionId: Int, event: KeyEvent?): Boolean {
12
+ if (isReadOnly()) return true
13
+ val isKeyUp = event?.action == KeyEvent.ACTION_UP
14
+ val isImeSend = actionId == EditorInfo.IME_ACTION_SEND && !isKeyUp
15
+ val isHardwareEnter = event?.keyCode == KeyEvent.KEYCODE_ENTER ||
16
+ event?.keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER
17
+ if (isImeSend || (isHardwareEnter && !isKeyUp)) sendEnter()
18
+ // An unconsumed Enter key-up makes a single-line TextView move focus to
19
+ // the next view, so the terminal stops receiving keys.
20
+ return isImeSend || isHardwareEnter
21
+ }
22
+}
apps/mobile/modules/t3-terminal/android/src/test/java/expo/modules/t3terminal/TerminalEnterListenerTest.kt
new
+51
@@ -0,0 +1,51 @@
1
+package expo.modules.t3terminal
2
+
3
+import android.app.Activity
4
+import android.view.KeyEvent
5
+import android.view.View
6
+import android.widget.Button
7
+import android.widget.EditText
8
+import android.widget.LinearLayout
9
+import org.junit.Assert.assertEquals
10
+import org.junit.Assert.assertTrue
11
+import org.junit.Test
12
+import org.junit.runner.RunWith
13
+import org.robolectric.Robolectric
14
+import org.robolectric.RobolectricTestRunner
15
+import org.robolectric.annotation.Config
16
+
17
+@RunWith(RobolectricTestRunner::class)
18
+@Config(sdk = [36], manifest = Config.NONE)
19
+class TerminalEnterListenerTest {
20
+ @Test
21
+ fun hardwareEnterKeepsFocusOnTheTerminalInput() {
22
+ val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
23
+ var sent = 0
24
+ val input = EditText(activity).apply {
25
+ setSingleLine(true)
26
+ isFocusableInTouchMode = true
27
+ setOnEditorActionListener(TerminalEnterListener({ false }) { sent += 1 })
28
+ }
29
+ val nextControl = Button(activity).apply { isFocusableInTouchMode = true }
30
+ val root = LinearLayout(activity).apply {
31
+ orientation = LinearLayout.VERTICAL
32
+ addView(input)
33
+ addView(nextControl)
34
+ }
35
+ activity.setContentView(root)
36
+ // Focus search below the input only finds controls that have bounds.
37
+ root.measure(
38
+ View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY),
39
+ View.MeasureSpec.makeMeasureSpec(1920, View.MeasureSpec.EXACTLY),
40
+ )
41
+ root.layout(0, 0, 1080, 1920)
42
+ assertTrue(input.requestFocus())
43
+
44
+ for (keyCode in listOf(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER)) {
45
+ input.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, keyCode))
46
+ input.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_UP, keyCode))
47
+ assertTrue("focus left the input after key $keyCode", input.isFocused)
48
+ }
49
+ assertEquals(2, sent)
50
+ }
51
+}