Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/eighty-ghosts-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capawesome/capacitor-app-shortcuts': minor
---

feat(android): string type support for `androidIcon`
2 changes: 1 addition & 1 deletion packages/app-shortcuts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Remove all listeners for this plugin.
| **`id`** | <code>string</code> | The unique identifier. | 6.0.0 |
| **`title`** | <code>string</code> | The display name. | 6.0.0 |
| **`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 |
| **`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 |
| **`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 |
| **`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 |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ public static List<ShortcutInfoCompat> createShortcutInfoCompatList(JSArray shor
(String) id
)
);

if (androidIcon != null) {
shortcutInfoCompat.setIcon(IconCompat.createWithResource(context, (int) androidIcon));
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));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-shortcuts/example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/app-shortcuts/example/src/js/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AppShortcuts } from '@capawesome/capacitor-app-shortcuts';
import { Capacitor } from '@capacitor/core';

document.addEventListener('DOMContentLoaded', () => {
const initialize = async () => {
Expand All @@ -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,
androidIcon: 17301547, // 'alert_dark_frame'
},
],
});
Expand Down
5 changes: 3 additions & 2 deletions packages/app-shortcuts/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +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
* @example "alert_dark_frame"
*/
androidIcon?: number;
androidIcon?: number | string;
/**
* The icon to display on iOS.
*
Expand Down