@devries-cameron20 / t3code-1 / commits / c73b38b379
Fork 0

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

fix(mobile): Android sends with Return on a hardware keyboard (#21687)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 9, 2026 at 14:45 UTC c73b38b379542cde87ec8bc855b70e7fae78fb5c
11 files changed +208 -14
apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorModule.kt
+8
@@ -66,6 +66,7 @@ internal object T3ComposerClipboard {
66 }
67
68 class T3ComposerEditorModule : Module() {
69 + @Suppress("LongMethod") // A flat list of the view's props and events.
70 override fun definition() = ModuleDefinition {
71 Name("T3ComposerEditor")
72
@@ -108,6 +109,12 @@ class T3ComposerEditorModule : Module() {
109 Prop("readOnly") { view: T3ComposerEditorView, readOnly: Boolean ->
110 view.setReadOnly(readOnly)
111 }
112 + Prop("enterBehavior") { view: T3ComposerEditorView, behavior: String ->
113 + view.setEnterBehavior(behavior)
114 + }
115 + Prop("submitEnabled") { view: T3ComposerEditorView, enabled: Boolean ->
116 + view.setSubmitEnabled(enabled)
117 + }
118 Prop("scrollEnabled") { view: T3ComposerEditorView, scrollEnabled: Boolean ->
119 view.setScrollEnabled(scrollEnabled)
120 }
@@ -132,6 +139,7 @@ class T3ComposerEditorModule : Module() {
139 "onComposerSelectionChange",
140 "onComposerFocus",
141 "onComposerBlur",
142 + "onComposerSubmit",
143 "onComposerPasteImages",
144 "onComposerContextPress",
145 "onComposerPasteContext",
apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
+54
@@ -21,6 +21,7 @@ import android.util.TypedValue
21 import android.view.DragEvent
22 import android.view.Gravity
23 import android.view.GestureDetector
24 +import android.view.InputDevice
25 import android.view.MotionEvent
26 import android.view.KeyEvent
27 import android.view.View
@@ -58,6 +59,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
59 private val onComposerSelectionChange by EventDispatcher()
60 private val onComposerFocus by EventDispatcher()
61 private val onComposerBlur by EventDispatcher()
62 + private val onComposerSubmit by EventDispatcher()
63 private val onComposerPasteImages by EventDispatcher()
64 private val onComposerContextPress by EventDispatcher()
65 private val onComposerPasteContext by EventDispatcher()
@@ -169,6 +171,9 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
171 ),
172 )
173 }
174 + editor.submitListener = { alternate ->
175 + onComposerSubmit(mapOf("alternate" to alternate))
176 + }
177 editor.setOnFocusChangeListener { _, hasFocus ->
178 if (hasFocus) {
179 onComposerFocus(emptyMap<String, Any>())
@@ -326,6 +331,14 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
331 editor.isCursorVisible = editor.isEnabled && !readOnly
332 }
333
334 + fun setEnterBehavior(behavior: String) {
335 + editor.returnSends = behavior != "newline"
336 + }
337 +
338 + fun setSubmitEnabled(enabled: Boolean) {
339 + editor.submitEnabled = enabled
340 + }
341 +
342 fun setScrollEnabled(scrollEnabled: Boolean) {
343 editor.isVerticalScrollBarEnabled = scrollEnabled
344 }
@@ -617,6 +630,9 @@ internal class SelectionAwareEditText(
630 var pasteImagesListener: ((List<String>) -> Unit)? = null
631 var pasteContextListener: ((Map<String, String>) -> Unit)? = null
632 var pasteTextListener: ((String, Int, Int) -> Unit)? = null
633 + var submitListener: ((Boolean) -> Unit)? = null
634 + var submitEnabled = false
635 + var returnSends = true
636 var textPasteThresholdBytes = 0
637 var maxInputChars = Int.MAX_VALUE
638 var clipboardFragment = ""
@@ -674,7 +690,45 @@ internal class SelectionAwareEditText(
690 return spans.isNotEmpty()
691 }
692
693 + // Mirrors the iOS key commands with Ctrl for Command. Returns `alternate`, or null to type Return.
694 + // No composing-text guard: some IMEs keep a composing region over the last word while hardware typing.
695 + private fun returnSubmission(keyCode: Int, event: KeyEvent): Boolean? {
696 + val isReturn = keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER
697 + if (!isReturn || !canSubmit() || !isFromPhysicalKeyboard(event)) return null
698 + return if (returnSends) {
699 + when {
700 + event.hasNoModifiers() -> false
701 + event.hasModifiers(KeyEvent.META_CTRL_ON) -> true
702 + else -> null
703 + }
704 + } else {
705 + when {
706 + event.hasModifiers(KeyEvent.META_CTRL_ON) -> false
707 + event.hasModifiers(KeyEvent.META_CTRL_ON or KeyEvent.META_SHIFT_ON) -> true
708 + else -> null
709 + }
710 + }
711 + }
712 +
713 + private fun canSubmit(): Boolean =
714 + submitEnabled && submitListener != null && !readOnly && isEnabled
715 +
716 + // IMEs can send Return from device 0 without FLAG_SOFT_KEYBOARD, so only a real alphabetic keyboard counts.
717 + private fun isFromPhysicalKeyboard(event: KeyEvent): Boolean {
718 + val device = event.device
719 + return (event.flags and KeyEvent.FLAG_SOFT_KEYBOARD) == 0 &&
720 + device != null &&
721 + !device.isVirtual &&
722 + device.keyboardType == InputDevice.KEYBOARD_TYPE_ALPHABETIC
723 + }
724 +
725 override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
726 + val alternate = returnSubmission(keyCode, event)
727 + if (alternate != null) {
728 + // A held Return repeats; send once and swallow the repeats instead of typing newlines.
729 + if (event.repeatCount == 0) submitListener?.invoke(alternate)
730 + return true
731 + }
732 val handled = when (keyCode) {
733 KeyEvent.KEYCODE_DEL -> deleteChip(true)
734 KeyEvent.KEYCODE_FORWARD_DEL -> deleteChip(false)
apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerSubmitTest.kt new
+111
@@ -0,0 +1,111 @@
1 +package expo.modules.t3composereditor
2 +
3 +import android.text.InputType
4 +import android.view.InputDevice
5 +import android.view.KeyCharacterMap
6 +import android.view.KeyEvent
7 +import org.junit.Assert.assertEquals
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.Shadows.shadowOf
13 +import org.robolectric.annotation.Config
14 +import org.robolectric.shadows.InputDeviceBuilder
15 +
16 +@RunWith(RobolectricTestRunner::class)
17 +@Config(sdk = [36], manifest = Config.NONE)
18 +class ComposerSubmitTest {
19 + private val sends = mutableListOf<Boolean>()
20 + private val editor = SelectionAwareEditText(RuntimeEnvironment.getApplication()).apply {
21 + inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
22 + submitEnabled = true
23 + submitListener = { alternate -> sends += alternate }
24 + }
25 +
26 + private fun keyboard(id: Int, type: Int = InputDevice.KEYBOARD_TYPE_ALPHABETIC): InputDevice =
27 + InputDeviceBuilder.newBuilder()
28 + .setId(id)
29 + .setSources(InputDevice.SOURCE_KEYBOARD)
30 + .setKeyboardType(type)
31 + .build()
32 +
33 + private fun pressReturn(
34 + metaState: Int = 0,
35 + device: InputDevice = keyboard(1),
36 + repeatCount: Int = 0,
37 + flags: Int = 0
38 + ) {
39 + val event = KeyEvent(
40 + 0,
41 + 0,
42 + KeyEvent.ACTION_DOWN,
43 + KeyEvent.KEYCODE_ENTER,
44 + repeatCount,
45 + metaState,
46 + device.id,
47 + 0,
48 + flags,
49 + )
50 + // Robolectric's getDevice() reads the event's shadow, not the InputManager device list.
51 + shadowOf(event).setDevice(device)
52 + editor.onKeyDown(KeyEvent.KEYCODE_ENTER, event)
53 + }
54 +
55 + @Test
56 + fun sendBehaviorSendsOnReturnAndInsertsANewlineOnShiftReturn() {
57 + pressReturn()
58 + pressReturn(KeyEvent.META_CTRL_ON or KeyEvent.META_CTRL_LEFT_ON)
59 + pressReturn(KeyEvent.META_SHIFT_ON or KeyEvent.META_SHIFT_LEFT_ON)
60 +
61 + assertEquals(listOf(false, true), sends)
62 + assertEquals("\n", editor.text.toString())
63 + }
64 +
65 + @Test
66 + fun newlineBehaviorSendsOnlyWithCtrl() {
67 + editor.returnSends = false
68 +
69 + pressReturn()
70 + pressReturn(KeyEvent.META_CTRL_ON)
71 + pressReturn(KeyEvent.META_CTRL_ON or KeyEvent.META_SHIFT_ON)
72 +
73 + assertEquals(listOf(false, true), sends)
74 + assertEquals("\n", editor.text.toString())
75 + }
76 +
77 + @Test
78 + fun onScreenKeyboardReturnInsertsANewline() {
79 + pressReturn(
80 + device = keyboard(KeyCharacterMap.VIRTUAL_KEYBOARD),
81 + flags = KeyEvent.FLAG_SOFT_KEYBOARD
82 + )
83 + // Some IMEs send device 0, the phone's key-only built-in "keyboard", without FLAG_SOFT_KEYBOARD.
84 + pressReturn(device = keyboard(0, InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC))
85 +
86 + assertEquals(emptyList<Boolean>(), sends)
87 + assertEquals("\n\n", editor.text.toString())
88 + }
89 +
90 + @Test
91 + fun heldReturnSendsOnce() {
92 + pressReturn()
93 + pressReturn(repeatCount = 1)
94 + pressReturn(repeatCount = 2)
95 +
96 + assertEquals(listOf(false), sends)
97 + assertEquals("", editor.text.toString())
98 + }
99 +
100 + @Test
101 + fun returnNeverSendsFromAComposerThatCannotSubmit() {
102 + editor.submitEnabled = false
103 + pressReturn()
104 + editor.submitEnabled = true
105 +
106 + editor.readOnly = true
107 + pressReturn()
108 +
109 + assertEquals(emptyList<Boolean>(), sends)
110 + }
111 +}
apps/mobile/src/features/settings/SettingsFollowUpRouteScreen.tsx
+2 -1
@@ -1,6 +1,7 @@
1 import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2 import { useAtomSet, useAtomValue } from "@effect/atom-react";
3 import { AsyncResult } from "effect/reactivity";
4 +import { Platform } from "react-native";
5 import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7 import { AppText as Text } from "../../components/ui/AppText";
@@ -59,7 +60,7 @@ export function SettingsFollowUpRouteScreen() {
60 </SettingsSection>
61 <Text className="px-2 text-sm text-foreground-muted">
62 Long-press the send button to use the other option for a single message. With a hardware
62 - keyboard, hold Command while sending.
63 + keyboard, hold {Platform.OS === "android" ? "Ctrl" : "Command"} while sending.
64 </Text>
65 </ScrollView>
66 );
apps/mobile/src/features/settings/SettingsKeyboardRouteScreen.tsx
+4 -1
@@ -1,6 +1,7 @@
1 import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2 import { useAtomSet, useAtomValue } from "@effect/atom-react";
3 import { AsyncResult } from "effect/reactivity";
4 +import { Platform } from "react-native";
5 import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7 import { AppText as Text } from "../../components/ui/AppText";
@@ -13,6 +14,8 @@ import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoi
14 import { SettingsScreen } from "./components/SettingsScreen";
15 import { SettingsSection } from "./components/SettingsSection";
16
17 +const SEND_MODIFIER = Platform.OS === "android" ? "Ctrl" : "Command";
18 +
19 const ENTER_BEHAVIOR_OPTIONS: ReadonlyArray<{
20 readonly behavior: ComposerEnterBehavior;
21 readonly label: string;
@@ -26,7 +29,7 @@ const ENTER_BEHAVIOR_OPTIONS: ReadonlyArray<{
29 {
30 behavior: "newline",
31 label: "Insert new line",
29 - description: "Return inserts a new line. Command-Return sends the message.",
32 + description: `Return inserts a new line. ${SEND_MODIFIER}-Return sends the message.`,
33 },
34 ];
35
apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+1 -1
@@ -246,7 +246,7 @@ function useSettingsIndexSections(): SettingsListSection[] {
246 ...(navigationCustomizationAvailable()
247 ? [page("SettingsNavigation", "line.3.horizontal", "Navigation tabs")]
248 : []),
249 - ...(Platform.OS === "ios" ? [page("SettingsKeyboard", "keyboard", "Keyboard")] : []),
249 + page("SettingsKeyboard", "keyboard", "Keyboard"),
250 page("SettingsVoice", "mic", "Voice"),
251 ],
252 },
apps/mobile/src/native/T3ComposerEditor.native.tsx
+12
@@ -2,6 +2,7 @@ import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/
2 import { PROVIDER_SEND_TURN_MAX_INPUT_CHARS } from "@t3tools/contracts";
3 import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
4 import { composerContextEditorTokens, composerSkillLabels } from "../lib/composerContext";
5 +import { DEFAULT_COMPOSER_ENTER_BEHAVIOR } from "../lib/composerEnterBehavior";
6 import { useComposerModelTokens } from "./useComposerModelTokens";
7 import { requireNativeView } from "expo";
8 import { TextInputWrapper } from "expo-paste-input";
@@ -91,6 +92,8 @@ interface NativeComposerEditorProps extends ViewProps {
92 readonly autoFocus: boolean;
93 readonly autoCorrect: boolean;
94 readonly spellCheck: boolean;
95 + readonly enterBehavior: string;
96 + readonly submitEnabled: boolean;
97 readonly onComposerChange: (event: NativeEditorEvent) => void;
98 readonly onComposerSelectionChange?: (event: NativeSelectionEvent) => void;
99 readonly onComposerPasteImages?: (event: NativePasteImagesEvent) => void;
@@ -108,6 +111,7 @@ interface NativeComposerEditorProps extends ViewProps {
111 readonly onComposerContentSizeChange?: (
112 event: NativeSyntheticEvent<{ readonly width: number; readonly height: number }>,
113 ) => void;
114 + readonly onComposerSubmit?: (event: NativeSyntheticEvent<{ alternate: boolean }>) => void;
115 }
116
117 const NativeView = requireNativeView<NativeComposerEditorProps>(NATIVE_MODULE_NAME);
@@ -138,6 +142,7 @@ export function ComposerEditor({
142 onFocus,
143 onBlur,
144 onContentSizeChange,
145 + onSubmit,
146 contentInsetVertical = 0,
147 ...props
148 }: ComposerEditorProps) {
@@ -339,6 +344,8 @@ export function ComposerEditor({
344 autoFocus={props.autoFocus ?? false}
345 autoCorrect={props.autoCorrect ?? true}
346 spellCheck={props.spellCheck ?? true}
347 + enterBehavior={props.enterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR}
348 + submitEnabled={onSubmit !== undefined}
349 textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
350 maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
351 style={{ flex: 1, minHeight: 0 }}
@@ -407,6 +414,11 @@ export function ComposerEditor({
414 ? undefined
415 : (event) => onContentSizeChange(event.nativeEvent)
416 }
417 + onComposerSubmit={
418 + onSubmit === undefined
419 + ? undefined
420 + : (event) => onSubmit(event.nativeEvent.alternate === true)
421 + }
422 />
423 </TextInputWrapper>
424 );
apps/mobile/src/native/T3ComposerEditor.types.ts
+2 -5
@@ -85,13 +85,10 @@ export interface ComposerEditorProps {
85 readonly width: number;
86 readonly height: number;
87 }) => void;
88 - /**
89 - * Hardware-keyboard Return behavior on iOS. No-op on Android, which has no
90 - * hardware Return handling.
91 - */
88 + /** Hardware-keyboard Return behavior. Soft keyboards always insert a newline. */
89 readonly enterBehavior?: ComposerEnterBehavior;
90 readonly submitTitle?: string;
91 readonly alternateSubmitTitle?: string;
95 - /** Command chords set alternate to reverse follow-up behavior; Android always passes false. */
92 + /** Command chords (Ctrl on Android) reverse the configured follow-up behavior. */
93 readonly onSubmit?: (alternate: boolean) => void;
94 }
apps/mobile/src/persistence/mobile-preferences.ts
+1 -1
@@ -110,7 +110,7 @@ export interface Preferences {
110 readonly connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
111 readonly collapsedProjectGroups?: readonly string[];
112 readonly dismissedDatabaseStorageNotices?: readonly string[];
113 - /** Hardware Return behavior is iOS-only. */
113 + /** Hardware-keyboard Return behavior in the composer. */
114 readonly composerEnterBehavior?: ComposerEnterBehavior;
115 readonly followUpBehavior?: FollowUpBehavior;
116 readonly microphones?: ReadonlyArray<MicrophoneEntry>;
docs/user/composer.md
+4 -2
@@ -85,8 +85,10 @@ start of the composer to edit the most recently queued message. Change
85
86 Mobile has the same choice under **Settings → Chat**. While a turn is
87 running the send button shows which action it will take. Long-press it to use the
88 -other action for a single message, or hold `Cmd` while sending from a hardware
89 -keyboard. The button only offers Steer when the running agent supports it.
88 +other action for a single message. From a hardware keyboard, `Cmd+Return`
89 +(`Ctrl+Return` on Android) uses the other action, or `Cmd+Shift+Return`
90 +(`Ctrl+Shift+Return`) when Return inserts a new line. The button only offers
91 +Steer when the running agent supports it.
92
93 ## Queue messages offline on mobile
94
docs/user/keybindings.md
+9 -3
@@ -80,9 +80,15 @@ to show only actions.
80
81 In a new thread, `Cmd+Shift+H` moves the draft to the next machine.
82
83 -In the composer, Return sends and `Shift+Return` inserts a new line. `Cmd+Return`
84 -also sends. To make Return insert a new line instead, change the Return key
85 -behavior in Settings → Keyboard.
83 +In the composer, Return sends and `Shift+Return` inserts a new line. While a
84 +turn is running, `Cmd+Return` sends with the other follow-up action. To make
85 +Return insert a new line instead, change the Return key behavior in Settings →
86 +Keyboard; `Cmd+Return` then sends.
87 +
88 +## Android
89 +
90 +With a hardware keyboard, the composer handles Return as on iPad, with `Ctrl` in
91 +place of `Cmd`. The on-screen keyboard's Return always inserts a new line.
92
93 ## Edit the configuration file
94