Skip to content

Commit 8a3ffb6

Browse files
alanleedevfacebook-github-bot
authored andcommitted
fix TextInput 'contextMenuHidden' prop (facebook#45014)
Summary: Pull Request resolved: facebook#45014 `TextInput`'s `contextMenuHidden` prop isn't working working as expected. It should hide the context menu (copy/paste/...) that pops up from input text. Reference: [Android doc](https://developer.android.com/reference/android/widget/TextView#setCustomSelectionActionModeCallback(android.view.ActionMode.Callback)) > Returning false from `ActionMode.Callback.onCreateActionMode(ActionMode, android.view.Menu)` will prevent the action mode from being started. **Changelog:** [Android][Fixed] - TextInput's `contextMenuHidden` prop bug fix Reviewed By: javache Differential Revision: D58684366 fbshipit-source-id: 328c267ed0e896a78e114578e3a00adf41f2e095
1 parent 75451d5 commit 8a3ffb6

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7739,6 +7739,7 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
77397739
public fun setBorderStyle (Ljava/lang/String;)V
77407740
public fun setBorderWidth (IF)V
77417741
public fun setContentSizeWatcher (Lcom/facebook/react/views/textinput/ContentSizeWatcher;)V
7742+
public fun setContextMenuHidden (Z)V
77427743
public fun setDisableFullscreenUI (Z)V
77437744
public fun setFontFamily (Ljava/lang/String;)V
77447745
public fun setFontFeatureSettings (Ljava/lang/String;)V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class ReactEditText extends AppCompatEditText {
118118
private int mFontWeight = ReactConstants.UNSET;
119119
private int mFontStyle = ReactConstants.UNSET;
120120
private boolean mAutoFocus = false;
121+
private boolean mContextMenuHidden = false;
121122
private boolean mDidAttachToWindow = false;
122123
private @Nullable String mPlaceholder = null;
123124

@@ -191,6 +192,9 @@ public boolean performAccessibilityAction(View host, int action, Bundle args) {
191192
*/
192193
@Override
193194
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
195+
if (mContextMenuHidden) {
196+
return false;
197+
}
194198
menu.removeItem(android.R.id.pasteAsPlainText);
195199
return true;
196200
}
@@ -1121,6 +1125,10 @@ public void setAutoFocus(boolean autoFocus) {
11211125
mAutoFocus = autoFocus;
11221126
}
11231127

1128+
public void setContextMenuHidden(boolean contextMenuHidden) {
1129+
mContextMenuHidden = contextMenuHidden;
1130+
}
1131+
11241132
protected void applyTextAttributes() {
11251133
// In general, the `getEffective*` functions return `Float.NaN` if the
11261134
// property hasn't been set.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,7 @@ && shouldHideCursorForEmailTextInput()) {
651651

652652
@ReactProp(name = "contextMenuHidden", defaultBoolean = false)
653653
public void setContextMenuHidden(ReactEditText view, boolean contextMenuHidden) {
654-
final boolean _contextMenuHidden = contextMenuHidden;
655-
view.setOnLongClickListener(
656-
new View.OnLongClickListener() {
657-
public boolean onLongClick(View v) {
658-
return _contextMenuHidden;
659-
}
660-
;
661-
});
654+
view.setContextMenuHidden(contextMenuHidden);
662655
}
663656

664657
@ReactProp(name = "selectTextOnFocus", defaultBoolean = false)

0 commit comments

Comments
 (0)