Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added selected option to actions #92

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ Optional. The title above the popup menu.

###### `actions`

Array of `{ title: string, subtitle?: string, systemIcon?: string, destructive?: boolean, disabled?: boolean, disabled?: boolean, inlineChildren?: boolean, actions?: Array<ContextMenuAction> }`.
Array of `{ title: string, subtitle?: string, systemIcon?: string, destructive?: boolean, selected?: boolean, disabled?: boolean, disabled?: boolean, inlineChildren?: boolean, actions?: Array<ContextMenuAction> }`.

Subtitle is only available on iOS 15+.

System icon refers to an icon name within [SF Symbols](https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/).

Destructive items are rendered in red on iOS, and unchanged on Android.

Selected items have a checkmark next to them on iOS, and unchanged on Android.

Nested menus are supported on iOS only and result in nested UIMenu which can be optionally displayed inline.

###### `onPress`
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface ContextMenuAction {
* Destructive items are rendered in red on iOS, and unchanged on Android. (default: false)
*/
destructive?: boolean;
/**
* Selected items have a checkmark next to them on iOS, and unchanged on Android. (default: false)
*/
selected?: boolean;
/**
* Whether the action is disabled or not (default: false)
*/
Expand Down
1 change: 1 addition & 0 deletions ios/ContextMenuAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@property (nonnull, nonatomic, copy) NSString* subtitle;
@property (nullable, nonatomic, copy) NSString* systemIcon;
@property (nonatomic, assign) BOOL destructive;
@property (nonatomic, assign) BOOL selected;
@property (nonatomic, assign) BOOL disabled;
@property (nonatomic, assign) BOOL inlineChildren;
@property (nullable, nonatomic, copy) NSArray<ContextMenuAction*>* actions;
Expand Down
3 changes: 3 additions & 0 deletions ios/ContextMenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ - (UIMenuElement*) createMenuElementForAction:(ContextMenuAction *)action atInde
(action.destructive ? UIMenuElementAttributesDestructive : 0) |
(action.disabled ? UIMenuElementAttributesDisabled : 0);

actionMenuItem.state =
action.selected ? UIMenuElementStateOn : UIMenuElementStateOff;

menuElement = actionMenuItem;
}

Expand Down
1 change: 1 addition & 0 deletions ios/RCTConvert+ContextMenuAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ + (ContextMenuAction*) ContextMenuAction:(id)json {
action.subtitle = [self NSString:json[@"subtitle"]];
action.systemIcon = [self NSString:json[@"systemIcon"]];
action.destructive = [self BOOL:json[@"destructive"]];
action.selected = [self BOOL:json[@"selected"]];
action.disabled = [self BOOL:json[@"disabled"]];
action.inlineChildren = [self BOOL:json[@"inlineChildren"]];

Expand Down