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 @@ -6251,6 +6251,7 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
public final fun maybeUpdateTypeface ()V
public fun onAttachedToWindow ()V
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
protected fun onCreateContextMenu (Landroid/view/ContextMenu;)V
public fun onCreateInputConnection (Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;
public fun onDragEvent (Landroid/view/DragEvent;)Z
public fun onDraw (Landroid/graphics/Canvas;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.text.method.KeyListener
import android.text.method.QwertyKeyListener
import android.util.TypedValue
import android.view.ActionMode
import android.view.ContextMenu
import android.view.DragEvent
import android.view.Gravity
import android.view.KeyEvent
Expand Down Expand Up @@ -388,6 +389,16 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
if (id == android.R.id.paste) android.R.id.pasteAsPlainText else id,
)

/*
* A secondary click opens the context menu that Editor fills with the text actions. With
* contextMenuHidden it gets no items, so no menu opens.
*/
override fun onCreateContextMenu(menu: ContextMenu) {
if (!contextMenuHidden) {
super.onCreateContextMenu(menu)
}
}

internal fun clearFocusAndMaybeRefocus() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P || !isInTouchMode) {
super.clearFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

package com.facebook.react.views.textinput

import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.os.Looper
import android.text.InputFilter
import android.text.InputFilter.AllCaps
import android.text.InputType
Expand Down Expand Up @@ -46,8 +48,10 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf

/** Verify {@link EditText} view property being applied properly by {@link ReactTextInputManager} */
@RunWith(RobolectricTestRunner::class)
Expand Down Expand Up @@ -652,6 +656,22 @@ class ReactTextInputPropertyTest {
.isNull()
}

@Test
fun testContextMenuHiddenRightClick() {
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
activity.setContentView(view)
view.setText("text")
shadowOf(Looper.getMainLooper()).idle()

// A mouse right-click opens the context menu at the pointer through showContextMenu(x, y),
// which answers whether a menu opened.
manager.updateProperties(view, buildStyles())
assertThat(view.showContextMenu(1f, 1f)).isTrue

manager.updateProperties(view, buildStyles("contextMenuHidden", true))
assertThat(view.showContextMenu(1f, 1f)).isFalse
}

private fun buildStyles(vararg keysAndValues: Any?): ReactStylesDiffMap {
return ReactStylesDiffMap(JavaOnlyMap.of(*keysAndValues))
}
Expand Down
Loading