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 cipolleschi committed Oct 7, 2024
1 parent e6ad652 commit 08eed9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class ReactEditText extends AppCompatEditText {
private int mFontWeight = UNSET;
private int mFontStyle = UNSET;
private boolean mAutoFocus = false;
private boolean mContextMenuHidden = false;
private boolean mDidAttachToWindow = false;
private @Nullable String mPlaceholder = null;

Expand Down Expand Up @@ -192,6 +193,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 @@ -1139,6 +1143,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 @@ -904,14 +904,15 @@ public void setReturnKeyLabel(ReactEditText view, String returnKeyLabel) {
}

@ReactPropGroup(
names = {
ViewProps.BORDER_RADIUS,
ViewProps.BORDER_TOP_LEFT_RADIUS,
ViewProps.BORDER_TOP_RIGHT_RADIUS,
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
ViewProps.BORDER_BOTTOM_LEFT_RADIUS
},
defaultFloat = YogaConstants.UNDEFINED)
names = {
ViewProps.BORDER_RADIUS,
ViewProps.BORDER_TOP_LEFT_RADIUS,
ViewProps.BORDER_TOP_RIGHT_RADIUS,
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
ViewProps.BORDER_BOTTOM_LEFT_RADIUS
},
defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderRadius(ReactEditText view, int index, float borderRadius) {
if (!YogaConstants.isUndefined(borderRadius)) {
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
Expand Down Expand Up @@ -954,14 +955,15 @@ public void setTextDecorationLine(ReactEditText view, @Nullable String textDecor
}

@ReactPropGroup(
names = {
ViewProps.BORDER_WIDTH,
ViewProps.BORDER_LEFT_WIDTH,
ViewProps.BORDER_RIGHT_WIDTH,
ViewProps.BORDER_TOP_WIDTH,
ViewProps.BORDER_BOTTOM_WIDTH,
},
defaultFloat = YogaConstants.UNDEFINED)
names = {
ViewProps.BORDER_WIDTH,
ViewProps.BORDER_LEFT_WIDTH,
ViewProps.BORDER_RIGHT_WIDTH,
ViewProps.BORDER_TOP_WIDTH,
ViewProps.BORDER_BOTTOM_WIDTH,
},
defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidth(ReactEditText view, int index, float width) {
if (!YogaConstants.isUndefined(width)) {
width = PixelUtil.toPixelFromDIP(width);
Expand All @@ -970,14 +972,15 @@ public void setBorderWidth(ReactEditText view, int index, float width) {
}

@ReactPropGroup(
names = {
"borderColor",
"borderLeftColor",
"borderRightColor",
"borderTopColor",
"borderBottomColor"
},
customType = "Color")
names = {
"borderColor",
"borderLeftColor",
"borderRightColor",
"borderTopColor",
"borderBottomColor"
},
customType = "Color"
)
public void setBorderColor(ReactEditText view, int index, Integer color) {
float rgbComponent =
color == null ? YogaConstants.UNDEFINED : (float) ((int) color & 0x00FFFFFF);
Expand Down

0 comments on commit 08eed9f

Please sign in to comment.