@@ -13,7 +13,11 @@ import android.text.Spanned
1313import android.text.TextWatcher
1414import android.text.style.ReplacementSpan
1515import android.view.Gravity
16+ import android.view.KeyEvent
1617import android.view.ViewGroup
18+ import android.view.inputmethod.EditorInfo
19+ import android.view.inputmethod.InputConnection
20+ import android.view.inputmethod.InputConnectionWrapper
1721import android.view.inputmethod.InputMethodManager
1822import android.widget.EditText
1923import expo.modules.kotlin.AppContext
@@ -31,6 +35,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
3135 private val onComposerSelectionChange by EventDispatcher ()
3236 private val onComposerFocus by EventDispatcher ()
3337 private val onComposerBlur by EventDispatcher ()
38+ private val onComposerSubmit by EventDispatcher ()
3439 private val onComposerPasteImages by EventDispatcher ()
3540 private val onComposerContentSizeChange by EventDispatcher ()
3641 private var applyingNativeValue = false
@@ -65,6 +70,11 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
6570 editor.pasteImagesListener = { uris ->
6671 onComposerPasteImages(mapOf (" uris" to uris))
6772 }
73+ // A bare Enter (no Shift) submits — mirrors iOS and desktop Enter=submit.
74+ // Empty payload matches the iOS `onComposerSubmit([:])` contract.
75+ editor.submitListener = {
76+ onComposerSubmit(emptyMap<String , Any >())
77+ }
6878 editor.setOnFocusChangeListener { _, hasFocus ->
6979 if (hasFocus) {
7080 onComposerFocus(emptyMap<String , Any >())
@@ -450,6 +460,47 @@ private fun parseTokens(value: String): List<ComposerToken> = try {
450460private class SelectionAwareEditText (context : Context ) : EditText(context) {
451461 var selectionListener: ((Int , Int ) -> Unit )? = null
452462 var pasteImagesListener: ((List <String >) -> Unit )? = null
463+ var submitListener: (() -> Unit )? = null
464+
465+ private fun isPlainEnter (keyCode : Int , event : KeyEvent ? ): Boolean {
466+ val isEnter = keyCode == KeyEvent .KEYCODE_ENTER || keyCode == KeyEvent .KEYCODE_NUMPAD_ENTER
467+ // Shift+Enter still inserts a newline; only an unmodified Enter submits.
468+ return isEnter && event?.isShiftPressed != true
469+ }
470+
471+ // Hardware keyboards (and soft keyboards that route Enter as a key event)
472+ // land here. Fire submit on the down edge and consume both edges so the
473+ // multi-line field never inserts the newline.
474+ override fun onKeyDown (keyCode : Int , event : KeyEvent ? ): Boolean {
475+ if (isPlainEnter(keyCode, event)) {
476+ submitListener?.invoke()
477+ return true
478+ }
479+ return super .onKeyDown(keyCode, event)
480+ }
481+
482+ override fun onKeyUp (keyCode : Int , event : KeyEvent ? ): Boolean {
483+ if (isPlainEnter(keyCode, event)) {
484+ return true
485+ }
486+ return super .onKeyUp(keyCode, event)
487+ }
488+
489+ // Soft keyboards that commit the newline as text (rather than a key event)
490+ // land here; an exact "\n" commit means a bare Return, so submit instead.
491+ // A multi-line paste ("a\nb") is unaffected because it is not exactly "\n".
492+ override fun onCreateInputConnection (outAttrs : EditorInfo ): InputConnection ? {
493+ val base = super .onCreateInputConnection(outAttrs) ? : return null
494+ return object : InputConnectionWrapper (base, false ) {
495+ override fun commitText (text : CharSequence? , newCursorPosition : Int ): Boolean {
496+ if (text?.toString() == " \n " ) {
497+ submitListener?.invoke()
498+ return true
499+ }
500+ return super .commitText(text, newCursorPosition)
501+ }
502+ }
503+ }
453504
454505 override fun onSelectionChanged (selStart : Int , selEnd : Int ) {
455506 super .onSelectionChanged(selStart, selEnd)
0 commit comments