Skip to content

Commit 34f5bc4

Browse files
authored
feat(app-shortcuts): string type support for androidIcon (#489)
* fix(app-shortcuts): use icon names Add `androidIconName` property to shortcut. * fix(app-shortcuts): use icon names Generate changeset. * fix(app-shortcuts): use icon names Remove `androidIconName`. * fix(app-shortcuts): use icon names Undo doc changes.
1 parent 7e876db commit 34f5bc4

6 files changed

Lines changed: 19 additions & 7 deletions

File tree

.changeset/eighty-ghosts-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capawesome/capacitor-app-shortcuts': minor
3+
---
4+
5+
feat(android): string type support for `androidIcon`

packages/app-shortcuts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Remove all listeners for this plugin.
242242
| **`id`** | <code>string</code> | The unique identifier. | 6.0.0 |
243243
| **`title`** | <code>string</code> | The display name. | 6.0.0 |
244244
| **`icon`** | <code>string \| number</code> | 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 |
245-
| **`androidIcon`** | <code>number</code> | 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 |
245+
| **`androidIcon`** | <code>string \| number</code> | 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 |
246246
| **`iosIcon`** | <code>string \| number</code> | 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 |
247247

248248

packages/app-shortcuts/android/src/main/java/io/capawesome/capacitorjs/plugins/appshortcuts/AppShortcutsHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ public static List<ShortcutInfoCompat> createShortcutInfoCompatList(JSArray shor
5757
(String) id
5858
)
5959
);
60+
6061
if (androidIcon != null) {
61-
shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon));
62+
try {
63+
int iconResId = context.getResources().getIdentifier((String) androidIcon, "drawable", "android");
64+
shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, iconResId));
65+
} catch (Exception exception) {
66+
shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon));
67+
}
6268
} else if (icon != null) {
6369
shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) icon));
6470
}

packages/app-shortcuts/example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-shortcuts/example/src/js/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AppShortcuts } from '@capawesome/capacitor-app-shortcuts';
2-
import { Capacitor } from '@capacitor/core';
32

43
document.addEventListener('DOMContentLoaded', () => {
54
const initialize = async () => {
@@ -24,7 +23,8 @@ document.addEventListener('DOMContentLoaded', () => {
2423
description: 'Let us know how we can improve',
2524
id: 'feedback',
2625
title: 'Feedback',
27-
icon: Capacitor.getPlatform() === 'ios' ? 6 : 17301547,
26+
iosIcon: 6,
27+
androidIcon: 17301547, // 'alert_dark_frame'
2828
},
2929
],
3030
});

packages/app-shortcuts/src/definitions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ export interface Shortcut {
132132
/**
133133
* The icon to display on Android.
134134
*
135-
* The icon is the constant integer value of the [R.drawable](https://developer.android.com/reference/android/R.drawable) enum (e.g. `17301547`).
135+
* 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"`).
136136
*
137137
* @since 7.2.0
138138
* @example 17301547
139+
* @example "alert_dark_frame"
139140
*/
140-
androidIcon?: number;
141+
androidIcon?: number | string;
141142
/**
142143
* The icon to display on iOS.
143144
*

0 commit comments

Comments
 (0)