From 3ffe92cb54b84d1565cf1753e53ed4c9b8feeada Mon Sep 17 00:00:00 2001 From: Ehsan Barooni <66495214+ebarooni@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:54:28 +0200 Subject: [PATCH 1/4] fix(app-shortcuts): use icon names Add `androidIconName` property to shortcut. --- .../plugins/appshortcuts/AppShortcutsHelper.java | 7 ++++++- packages/app-shortcuts/example/package-lock.json | 2 +- packages/app-shortcuts/example/src/js/script.js | 4 ++-- packages/app-shortcuts/src/definitions.ts | 11 ++++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java b/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java index 4fc3db239..c8e6309cf 100644 --- a/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java +++ b/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java @@ -45,6 +45,7 @@ public static List createShortcutInfoCompatList(JSArray shor String description = (String) shortcutMap.get("description"); Object icon = shortcutMap.get("icon"); Object androidIcon = shortcutMap.get("androidIcon"); + Object androidIconName = shortcutMap.get("androidIconName"); ShortcutInfoCompat.Builder shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, (String) id); shortcutInfoCompat.setShortLabel((String) title); @@ -57,7 +58,11 @@ public static List createShortcutInfoCompatList(JSArray shor (String) id ) ); - if (androidIcon != null) { + + if (androidIconName != null) { + int iconResId = context.getResources().getIdentifier((String) androidIconName, "drawable", "android"); + shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, iconResId)); + } else if (androidIcon != null) { shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon)); } else if (icon != null) { shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) icon)); diff --git a/packages/app-shortcuts/example/package-lock.json b/packages/app-shortcuts/example/package-lock.json index 2a12023df..302c0563c 100644 --- a/packages/app-shortcuts/example/package-lock.json +++ b/packages/app-shortcuts/example/package-lock.json @@ -20,7 +20,7 @@ }, "..": { "name": "@capawesome/capacitor-app-shortcuts", - "version": "7.1.0", + "version": "7.2.0", "funding": [ { "type": "github", diff --git a/packages/app-shortcuts/example/src/js/script.js b/packages/app-shortcuts/example/src/js/script.js index 011468c62..fc81aee34 100644 --- a/packages/app-shortcuts/example/src/js/script.js +++ b/packages/app-shortcuts/example/src/js/script.js @@ -1,5 +1,4 @@ import { AppShortcuts } from '@capawesome/capacitor-app-shortcuts'; -import { Capacitor } from '@capacitor/core'; document.addEventListener('DOMContentLoaded', () => { const initialize = async () => { @@ -24,7 +23,8 @@ document.addEventListener('DOMContentLoaded', () => { description: 'Let us know how we can improve', id: 'feedback', title: 'Feedback', - icon: Capacitor.getPlatform() === 'ios' ? 6 : 17301547, + iosIcon: 6, + androidIconName: 'btn_plus', }, ], }); diff --git a/packages/app-shortcuts/src/definitions.ts b/packages/app-shortcuts/src/definitions.ts index 112897e05..2c8b1cea9 100644 --- a/packages/app-shortcuts/src/definitions.ts +++ b/packages/app-shortcuts/src/definitions.ts @@ -123,7 +123,7 @@ export interface Shortcut { * - Name of the image asset from the asset catalogue. * * @since 6.1.0 - * @deprecated Use `androidIcon` and `iosIcon` instead. + * @deprecated Use `androidIcon`, `androidIconName` and `iosIcon` instead. * @example 17301547 * @example 6 * @example "star.fill" @@ -138,6 +138,15 @@ export interface Shortcut { * @example 17301547 */ androidIcon?: number; + /** + * The icon to display on Android. + * + * The icon is the constants of [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `"alert_dark_frame"`). + * + * @since 7.3.0 + * @example "alert_dark_frame" + */ + androidIconName?: string; /** * The icon to display on iOS. * From f09e860cf9bc77c2353816ca2522565089580fb2 Mon Sep 17 00:00:00 2001 From: Ehsan Barooni <66495214+ebarooni@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:56:57 +0200 Subject: [PATCH 2/4] fix(app-shortcuts): use icon names Generate changeset. --- .changeset/eighty-ghosts-count.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eighty-ghosts-count.md diff --git a/.changeset/eighty-ghosts-count.md b/.changeset/eighty-ghosts-count.md new file mode 100644 index 000000000..28b3bfbaf --- /dev/null +++ b/.changeset/eighty-ghosts-count.md @@ -0,0 +1,5 @@ +--- +'@capawesome/capacitor-app-shortcuts': minor +--- + +fix(android): add `androidIconName` to `Shortcut` From c4d9ce6b86ec156b48a127194ea65908e5eb0dd9 Mon Sep 17 00:00:00 2001 From: Ehsan Barooni <66495214+ebarooni@users.noreply.github.com> Date: Mon, 21 Apr 2025 22:23:45 +0200 Subject: [PATCH 3/4] fix(app-shortcuts): use icon names Remove `androidIconName`. --- .changeset/eighty-ghosts-count.md | 2 +- packages/app-shortcuts/README.md | 2 +- .../plugins/appshortcuts/AppShortcutsHelper.java | 13 +++++++------ packages/app-shortcuts/example/src/js/script.js | 2 +- packages/app-shortcuts/src/definitions.ts | 12 ++---------- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/.changeset/eighty-ghosts-count.md b/.changeset/eighty-ghosts-count.md index 28b3bfbaf..57911bdf0 100644 --- a/.changeset/eighty-ghosts-count.md +++ b/.changeset/eighty-ghosts-count.md @@ -1,5 +1,5 @@ --- -'@capawesome/capacitor-app-shortcuts': minor +'@capawesome/capacitor-app-shortcuts': patch --- fix(android): add `androidIconName` to `Shortcut` diff --git a/packages/app-shortcuts/README.md b/packages/app-shortcuts/README.md index 0cef32278..f3bf90004 100644 --- a/packages/app-shortcuts/README.md +++ b/packages/app-shortcuts/README.md @@ -242,7 +242,7 @@ Remove all listeners for this plugin. | **`id`** | string | The unique identifier. | 6.0.0 | | **`title`** | string | The display name. | 6.0.0 | | **`icon`** | string \| number | The icon to display. On **Android**, the icon is the constant integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`). On **iOS**, the icon can be one of the following: - The constant integer value of the [UIApplicationShortcutIcon.IconType](https://developer.apple.com/documentation/uikit/uiapplicationshortcuticon/icontype) enum (e.g. `6`). - A system symbol name (e.g. `star.fill`). - Name of the image asset from the asset catalogue. | 6.1.0 | -| **`androidIcon`** | number | The icon to display on Android. The icon is the constant integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`). | 7.2.0 | +| **`androidIcon`** | string \| number | The icon to display on Android. The icon is the constant name or the integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`, `"alert_dark_frame"`). | 7.2.0 | | **`iosIcon`** | string \| number | The icon to display on iOS. The icon can be one of the following: - The constant integer value of the [UIApplicationShortcutIcon.IconType](https://developer.apple.com/documentation/uikit/uiapplicationshortcuticon/icontype) enum (e.g. `6`). - A system symbol name (e.g. `star.fill`). - Name of the image asset from the asset catalogue. | 7.2.0 | diff --git a/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java b/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java index c8e6309cf..45b3e9eca 100644 --- a/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java +++ b/packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java @@ -45,7 +45,6 @@ public static List createShortcutInfoCompatList(JSArray shor String description = (String) shortcutMap.get("description"); Object icon = shortcutMap.get("icon"); Object androidIcon = shortcutMap.get("androidIcon"); - Object androidIconName = shortcutMap.get("androidIconName"); ShortcutInfoCompat.Builder shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, (String) id); shortcutInfoCompat.setShortLabel((String) title); @@ -59,11 +58,13 @@ public static List createShortcutInfoCompatList(JSArray shor ) ); - if (androidIconName != null) { - int iconResId = context.getResources().getIdentifier((String) androidIconName, "drawable", "android"); - shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, iconResId)); - } else if (androidIcon != null) { - shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon)); + if (androidIcon != null) { + try { + int iconResId = context.getResources().getIdentifier((String) androidIcon, "drawable", "android"); + shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, iconResId)); + } catch (Exception exception) { + shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon)); + } } else if (icon != null) { shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) icon)); } diff --git a/packages/app-shortcuts/example/src/js/script.js b/packages/app-shortcuts/example/src/js/script.js index fc81aee34..eb7d20c99 100644 --- a/packages/app-shortcuts/example/src/js/script.js +++ b/packages/app-shortcuts/example/src/js/script.js @@ -24,7 +24,7 @@ document.addEventListener('DOMContentLoaded', () => { id: 'feedback', title: 'Feedback', iosIcon: 6, - androidIconName: 'btn_plus', + androidIcon: 17301547, }, ], }); diff --git a/packages/app-shortcuts/src/definitions.ts b/packages/app-shortcuts/src/definitions.ts index 2c8b1cea9..76eab943b 100644 --- a/packages/app-shortcuts/src/definitions.ts +++ b/packages/app-shortcuts/src/definitions.ts @@ -132,21 +132,13 @@ export interface Shortcut { /** * The icon to display on Android. * - * The icon is the constant integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`). + * The icon is the constant name or the integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`, `"alert_dark_frame"`). * * @since 7.2.0 * @example 17301547 - */ - androidIcon?: number; - /** - * The icon to display on Android. - * - * The icon is the constants of [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `"alert_dark_frame"`). - * - * @since 7.3.0 * @example "alert_dark_frame" */ - androidIconName?: string; + androidIcon?: number | string; /** * The icon to display on iOS. * From 2ce49069f15c87b981dd01b7c5770414fbf9d2ee Mon Sep 17 00:00:00 2001 From: Ehsan Barooni <66495214+ebarooni@users.noreply.github.com> Date: Tue, 22 Apr 2025 10:53:56 +0200 Subject: [PATCH 4/4] fix(app-shortcuts): use icon names Undo doc changes. --- .changeset/eighty-ghosts-count.md | 4 ++-- packages/app-shortcuts/example/src/js/script.js | 2 +- packages/app-shortcuts/src/definitions.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.changeset/eighty-ghosts-count.md b/.changeset/eighty-ghosts-count.md index 57911bdf0..324c8638b 100644 --- a/.changeset/eighty-ghosts-count.md +++ b/.changeset/eighty-ghosts-count.md @@ -1,5 +1,5 @@ --- -'@capawesome/capacitor-app-shortcuts': patch +'@capawesome/capacitor-app-shortcuts': minor --- -fix(android): add `androidIconName` to `Shortcut` +feat(android): string type support for `androidIcon` diff --git a/packages/app-shortcuts/example/src/js/script.js b/packages/app-shortcuts/example/src/js/script.js index eb7d20c99..121bfdf6b 100644 --- a/packages/app-shortcuts/example/src/js/script.js +++ b/packages/app-shortcuts/example/src/js/script.js @@ -24,7 +24,7 @@ document.addEventListener('DOMContentLoaded', () => { id: 'feedback', title: 'Feedback', iosIcon: 6, - androidIcon: 17301547, + androidIcon: 17301547, // 'alert_dark_frame' }, ], }); diff --git a/packages/app-shortcuts/src/definitions.ts b/packages/app-shortcuts/src/definitions.ts index 76eab943b..60f213ebc 100644 --- a/packages/app-shortcuts/src/definitions.ts +++ b/packages/app-shortcuts/src/definitions.ts @@ -123,7 +123,7 @@ export interface Shortcut { * - Name of the image asset from the asset catalogue. * * @since 6.1.0 - * @deprecated Use `androidIcon`, `androidIconName` and `iosIcon` instead. + * @deprecated Use `androidIcon` and `iosIcon` instead. * @example 17301547 * @example 6 * @example "star.fill"