From 3dde288c07624b8bb4611013dd14c5e9d9b01777 Mon Sep 17 00:00:00 2001 From: Vidocq Date: Sun, 3 Dec 2023 01:52:02 +0800 Subject: [PATCH] feat(android): support set icon color --- README.md | 4 +++- .../mpiannucci/reactnativecontextmenu/ContextMenuView.java | 5 +++++ index.d.ts | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06fe307..c1b391d 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,14 @@ Optional. The title above the popup menu. ###### `actions` -Array of `{ title: string, subtitle?: string, systemIcon?: string, destructive?: boolean, selected?: boolean, disabled?: boolean, disabled?: boolean, inlineChildren?: boolean, actions?: Array }`. +Array of `{ title: string, subtitle?: string, systemIcon?: string, systemIconColor?: string, destructive?: boolean, selected?: boolean, disabled?: boolean, disabled?: boolean, inlineChildren?: boolean, actions?: Array }`. 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/) on IOS and Drawable name on Android. +System icon color is only available on Android. + Destructive items are rendered in red. Selected items have a checkmark next to them on iOS, and unchanged on Android. diff --git a/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java b/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java index 7554774..02276bd 100644 --- a/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java +++ b/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java @@ -114,6 +114,11 @@ public void setActions(@Nullable ReadableArray actions) { int order = i; menu.add(Menu.NONE, Menu.NONE, order, title); menu.getItem(i).setEnabled(!action.hasKey("disabled") || !action.getBoolean("disabled")); + + if (action.hasKey("systemIconColor") && systemIcon != null) { + int color = Color.parseColor(action.getString("systemIconColor")); + systemIcon.setTint(color); + } menu.getItem(i).setIcon(systemIcon); if (action.hasKey("destructive") && action.getBoolean("destructive")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/index.d.ts b/index.d.ts index cb877d7..3df16e3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -14,6 +14,10 @@ export interface ContextMenuAction { * The icon to use. This is the name of the SFSymbols icon to use on IOS and name of the Drawable to use on Android. */ systemIcon?: string; + /** + * Color of icon. (Android only) + */ + systemIconColor?: string; /** * Destructive items are rendered in red on iOS, and unchanged on Android. (default: false) */