Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/capacitor-community/app-icon

Capacitor plugin to programmatically change the app icon.
https://github.com/capacitor-community/app-icon

capacitor capacitor-plugin

Last synced: 1 day ago
JSON representation

Capacitor plugin to programmatically change the app icon.

Awesome Lists containing this project

README

        



App Icon


@capacitor-community/app-icon



Capacitor community plugin for managing an app's icon. The main feature being that you can programmatically change the app icon.









## Maintainers

| Maintainer | GitHub | Social |
| ----------- | ------------------------------------------- | --------------------------------------------- |
| John Borges | [johnborges](https://github.com/johnborges) | [@johnborges](https://twitter.com/johnborges) |

## Before Starting

> This plugin only changes the main app icon on the device homescreen. The icon in springboard and in other areas will not change and continue to show the original. (iOS)

> Changing the app icon is only allowed when the app is in the foreground (iOS).

> Android support is currently in beta. See the [android-support](https://github.com/capacitor-community/app-icon/tree/android-support) branch for more info.

## Installation

```bash
npm install @capacitor-community/app-icon
npx cap sync
```

## Configuration

The alternate icons need to be included within the app bundle and referenced in the project prior to using this plugin. It is not possible to switch to any icon on the fly without adding it to the project first. Below are the configurations steps for each platform.

## Android Configuration

### Add Alternate Icons

Add the alternate icons directly to your android project in `app/src/main/res`.

### Setup ApplicationManifest.xml

Each alternate icon is represented by an [``](https://developer.android.com/guide/topics/manifest/activity-alias-element). Add all the alternative icons to the `ApplicationManifest.xml` as child elements under ``. The `name` attribute on `` must be prefixed with dot `.` See [ApplicationManifest.xml](https://github.com/capacitor-community/app-icon/blob/android-support/example/android/app/src/main/AndroidManifest.xml) for full example.

```xml













```

## iOS Configuration

> Taken from https://www.youtube.com/watch?v=AT89ofYpWTU

### Create the alternate icons in assets catalog

In XCode go to Assets and create the App Icons.
Then fill with images 1024x1024px

![XCode Assets Alternate Icons](./media/xcode_assets.png)

> The name of the asset should correspond to the name used in the code

### Change build settings

1. Visit Build Settings
2. Search For App icon,
3. Select "yes" for `Include All App Icon Assets`
4. Include a list (in `Alternate App Icon Sets`) with precise names of the app icons in the Assets Catalogue.

![Build Settings XCode](./media/xcode_build_settings.png)

## Usage

```javascript
import { AppIcon } from '@capacitor-community/app-icon';

const changeIcon = async (iconName) => {
await AppIcon.change({name: iconName, suppressNotification: true});
}

const getName = async () => {
const { value } = await AppIcon.getName();
console.log(value);
}

const resetIcon = async () => {
const disable: string[] = ['stencil']; // all added aliaces names
await AppIcon.reset({ suppressNotification: true, disable });
}
```

## API

* [`isSupported()`](#issupported)
* [`getName()`](#getname)
* [`change(...)`](#change)
* [`reset(...)`](#reset)
* [Interfaces](#interfaces)

### isSupported()

```typescript
isSupported() => Promise<{ value: boolean; }>
```

Checks if changing the app icon is supported. (iOS only)

**Returns:** Promise<{ value: boolean; }>

**Since:** 1.0.0

--------------------

### getName()

```typescript
getName() => Promise<{ value: string | null; }>
```

Gets the name of currently set alternate icon. If original icon is set, returns null.

**Returns:** Promise<{ value: string | null; }>

**Since:** 1.0.0

--------------------

### change(...)

```typescript
change(options: IconOptions) => Promise
```

Changes app icon to specified alternate.

| Param | Type |
| ------------- | --------------------------------------------------- |
| **`options`** | IconOptions |

**Since:** 1.0.0

--------------------

### reset(...)

```typescript
reset(options: ResetOptions) => Promise
```

Reverts app icon to original.

| Param | Type |
| ------------- | ----------------------------------------------------- |
| **`options`** | ResetOptions |

**Since:** 1.0.0

--------------------

### Interfaces

#### IconOptions

| Prop | Type | Description | Since |
| -------------------------- | --------------------- | --------------------------------------------------------------------------------- | ----- |
| **`name`** | string | Name of alternate icon to set | |
| **`disable`** | string[] | Name of icons to disable. This is not used for iOS, but required for Android. | 3.1.0 |
| **`suppressNotification`** | boolean | Flag controlling the in app notification which shows after icon is changed. (iOS) | |

#### ResetOptions

| Prop | Type | Description | Since |
| -------------------------- | --------------------- | --------------------------------------------------------------------------------- | ----- |
| **`suppressNotification`** | boolean | Flag controlling the in app notification which shows after icon is changed (iOS). | |
| **`disable`** | string[] | Name of icons to disable. This is not used for iOS, but required for Android. | 3.1.1 |

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



John Borges
John Borges

💻
Simon Grimm
Simon Grimm

💻
Christian von Rohr
Christian von Rohr

💻
QliQ.dev
QliQ.dev

💻
Hadouin
Hadouin

📖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!