From 02736ea1e546148a418d6dda23b26cd4b4d8fb38 Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Fri, 16 Oct 2026 00:17:15 +0300 Subject: [PATCH] Android: a TextInput with its context menu hidden takes no long press A long press on an Android TextInput selects the word under the finger and focuses the field so the text action menu can act on the selection. With contextMenuHidden set the menu never opens, so the long press only selected a word nothing could act on and focused the field with the keyboard down. ReactEditText is not long-clickable while contextMenuHidden is set: View never starts the long press, accessibility no longer offers one, and a press held on the field ends as a click when it lifts on it. TextView turns long-clicking back on when setInputType sets a key listener and when onAttachedToWindow makes the text selectable, so the gate sits in setLongClickable. --- .../ReactAndroid/api/ReactAndroid.api | 1 + .../react/views/textinput/ReactEditText.kt | 8 +++++++ .../textinput/ReactTextInputPropertyTest.kt | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 6c76d3a2197f..54e1eec5b853 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -6284,6 +6284,7 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp public fun setInputType (I)V public final fun setLetterSpacingPt (F)V public fun setLineHeight (I)V + public fun setLongClickable (Z)V public final fun setMaxFontSizeMultiplier (F)V protected final fun setNativeEventCount (I)V public final fun setOnKeyPress (Z)V 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 754f10026624..921d1e6c5bbd 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 @@ -1126,6 +1126,14 @@ public open class ReactEditText public constructor(context: Context) : AppCompat public fun setContextMenuHidden(contextMenuHidden: Boolean) { this.contextMenuHidden = contextMenuHidden + isLongClickable = !contextMenuHidden + } + + // A long press selects text for the menu that contextMenuHidden hides, so the field takes none + // while the menu is hidden. TextView turns long-clicking back on whenever setInputType sets a key + // listener and when onAttachedToWindow makes the text selectable, so the gate is in the setter. + override fun setLongClickable(longClickable: Boolean) { + super.setLongClickable(longClickable && !contextMenuHidden) } protected fun applyTextAttributes() { diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt index 82ec014eb89e..0a3997cf3cad 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt @@ -242,6 +242,28 @@ class ReactTextInputPropertyTest { assertThat(view.isEnabled).isTrue } + @Test + fun testContextMenuHidden() { + manager.updateProperties(view, buildStyles()) + assertThat(view.isLongClickable).isTrue + + manager.updateProperties(view, buildStyles("contextMenuHidden", true)) + assertThat(view.isLongClickable).isFalse + + manager.updateProperties(view, buildStyles("contextMenuHidden", true)) + assertThat(view.isLongClickable).isFalse + + // TextView turns long-clicking back on when a keyboard change sets a key listener and when + // attaching to a window makes the text selectable. + manager.updateProperties(view, buildStyles("keyboardType", "numeric")) + assertThat(view.isLongClickable).isFalse + view.setTextIsSelectable(true) + assertThat(view.isLongClickable).isFalse + + manager.updateProperties(view, buildStyles("contextMenuHidden", false)) + assertThat(view.isLongClickable).isTrue + } + @Test fun testAutoCompleteExtendedHints() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {