Skip to content

Commit

Permalink
feat(android): support disable menu
Browse files Browse the repository at this point in the history
  • Loading branch information
VidocqH authored and mpiannucci committed Nov 8, 2023
1 parent d3c8b8c commit 8517ad4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ Optional. When set to `true`, the context menu is triggered with a single tap in

###### `disabled`

Optional. Currently iOS only. Disable menu interaction.
Optional. Disable menu interaction.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void setDropdownMenuMode(ContextMenuView view, @Nullable boolean enabled)
view.setDropdownMenuMode(enabled);
}

@ReactProp(name = "disabled")
public void setDisabled(ContextMenuView view, @Nullable boolean disabled) {
view.setDisabled(disabled);
}

@androidx.annotation.Nullable
@Override
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public Action(String title, boolean disabled) {

protected boolean dropdownMenuMode = false;

protected boolean disabled = false;

public ContextMenuView(final Context context) {
super(context);

Expand Down Expand Up @@ -105,6 +107,8 @@ public void setActions(@Nullable ReadableArray actions) {
Menu menu = contextMenu.getMenu();
menu.clear();

if (disabled) { return; }

for (int i = 0; i < actions.size(); i++) {
ReadableMap action = actions.getMap(i);
@Nullable Drawable systemIcon = getResourceWithName(getContext(), action.getString("systemIcon"));
Expand All @@ -128,6 +132,10 @@ public void setDropdownMenuMode(@Nullable boolean enabled) {
this.dropdownMenuMode = enabled;
}

public void setDisabled(@Nullable boolean disabled) {
this.disabled = disabled;
}

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
cancelled = false;
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ContextMenuProps extends ViewProps {
*/
dropdownMenuMode?: boolean;
/**
* Currently iOS only. Disable menu interaction
* Disable menu interaction
*/
disabled?: boolean;
/**
Expand Down

0 comments on commit 8517ad4

Please sign in to comment.