diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt index 0415dca1126..c967b1c29bc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt @@ -258,6 +258,13 @@ public open class ReactEditText public constructor(context: Context) : AppCompat if (contextMenuHidden) { return false } + // setTextIsSelectable(true) (see onAttachedToWindow) makes the platform Editor + // treat this view as read-only selectable text and skip its "Show the IME to be + // able to replace text" branch when a selection or insertion action mode starts + // (Editor#startActionModeInternal gates it on !isTextSelectable()). Compensate + // here so long-pressing an editable input summons the keyboard, matching stock + // EditText behavior. + showSoftKeyboardIfEditable() menu.removeItem(android.R.id.pasteAsPlainText) return true } @@ -499,6 +506,14 @@ public open class ReactEditText public constructor(context: Context) : AppCompat if (focused && selectionWatcher != null) { selectionWatcher?.onSelectionChanged(selectionStart, selectionEnd) } + // Gaining focus with a non-collapsed selection means focus arrived through a + // long-press text selection rather than a tap or programmatic focus — the one focus + // path that never requests the soft keyboard (see onCreateActionMode). The action + // mode can be created before this view becomes the IME-served view, so request the + // keyboard again now that focus has landed. + if (focused && hasSelection()) { + showSoftKeyboardIfEditable() + } } internal fun setSelectionWatcher(selectionWatcher: SelectionWatcher?) { @@ -909,6 +924,14 @@ public open class ReactEditText public constructor(context: Context) : AppCompat protected fun showSoftKeyboard(): Boolean = inputMethodManager.showSoftInput(this, 0) + // Mirrors the guard on requestFocusProgrammatically(), plus editability ("editable" + // prop maps to isEnabled): never summon the keyboard for a read-only input. + private fun showSoftKeyboardIfEditable() { + if (isEnabled && isInTouchMode && showSoftInputOnFocus) { + showSoftKeyboard() + } + } + protected fun hideSoftKeyboard() { inputMethodManager.hideSoftInputFromWindow(windowToken, 0) }