Skip to content

Commit

Permalink
fix TextInput 'contextMenuHidden' prop (#45014)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
alanleedev authored and blakef committed Sep 30, 2024
1 parent 1e611fd commit 366f1d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 366f1d0

Please sign in to comment.