diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 6a14ffd1705780..cfdade228fc841 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7732,6 +7732,7 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp public fun setBorderStyle (Ljava/lang/String;)V public fun setBorderWidth (IF)V public fun setContentSizeWatcher (Lcom/facebook/react/views/textinput/ContentSizeWatcher;)V + public fun setContextMenuHidden (Z)V public fun setDisableFullscreenUI (Z)V public fun setFontFamily (Ljava/lang/String;)V public fun setFontFeatureSettings (Ljava/lang/String;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 014e0b489dd340..92cd700113c86e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -118,6 +118,7 @@ public class ReactEditText extends AppCompatEditText { private int mFontWeight = ReactConstants.UNSET; private int mFontStyle = ReactConstants.UNSET; private boolean mAutoFocus = false; + private boolean mContextMenuHidden = false; private boolean mDidAttachToWindow = false; private @Nullable String mPlaceholder = null; @@ -191,6 +192,9 @@ public boolean performAccessibilityAction(View host, int action, Bundle args) { */ @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { + if (mContextMenuHidden) { + return false; + } menu.removeItem(android.R.id.pasteAsPlainText); return true; } @@ -1121,6 +1125,10 @@ public void setAutoFocus(boolean autoFocus) { mAutoFocus = autoFocus; } + public void setContextMenuHidden(boolean contextMenuHidden) { + mContextMenuHidden = contextMenuHidden; + } + protected void applyTextAttributes() { // In general, the `getEffective*` functions return `Float.NaN` if the // property hasn't been set. diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 2c225da1554890..a0e92290e417c6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -651,14 +651,7 @@ && shouldHideCursorForEmailTextInput()) { @ReactProp(name = "contextMenuHidden", defaultBoolean = false) public void setContextMenuHidden(ReactEditText view, boolean contextMenuHidden) { - final boolean _contextMenuHidden = contextMenuHidden; - view.setOnLongClickListener( - new View.OnLongClickListener() { - public boolean onLongClick(View v) { - return _contextMenuHidden; - } - ; - }); + view.setContextMenuHidden(contextMenuHidden); } @ReactProp(name = "selectTextOnFocus", defaultBoolean = false)