Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading