@howincodes/expo-dynamic-app-icon
Version:
Programmatically change the app icon in Expo.
189 lines (137 loc) β’ 5.11 kB
Markdown
Easily **change your app icon dynamically** in **Expo SDK 52**!
β¨ **Android icon change without app restart!**
β¨ Seamless icon updates while the app stays running
β¨ Improved stability and performance
β
Reset icon to default
β
Support for **round icons**
β
Different icons for **iOS and Android**
β
Dynamic icon variants for **iOS** (light, dark, tinted)
β
iOS icon update **with or without alert popup**
β
**Simple API** to get and set the app icon

---
```sh
npx expo install @howincodes/expo-dynamic-app-icon
```
---
Add the plugin to your `app.json`:
```json
"plugins": [
[
"@howincodes/expo-dynamic-app-icon",
{
"red": {
"ios": "./assets/ios_icon1.png",
"android": "./assets/android_icon1.png"
},
"gray": {
"android": "./assets/icon2.png"
},
"dynamic": {
"ios": {
"light": "./assets/ios_icon_light.png",
"dark": "./assets/ios_icon_dark.png",
"tinted": "./assets/ios_icon_tinted.png"
}
}
}
]
]
```
---
Run the following command:
```sh
expo prebuild
```
Then, check if the following lines have been added to `AndroidManifest.xml`:
```xml
<activity-alias
android:name="expo.modules.dynamicappicon.example.MainActivityred"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/red"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
<activity-alias
android:name="expo.modules.dynamicappicon.example.MainActivitygray"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/gray"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
```
---
```typescript
import { setAppIcon } from "@howincodes/expo-dynamic-app-icon";
/**
* Change app icon to 'red'
*/
setAppIcon("red");
/**
* Reset to default icon
*/
setAppIcon(null);
```
```typescript
setAppIcon(
name: IconName | null,
isInBackground?: boolean
)
```
| Parameter | Type | Default | Description |
| ---------------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `name` | `IconName \| null` | `null` | The icon name to switch to. Pass `null` to reset to the default icon. |
| `isInBackground` | `boolean` | `true` | - `true`: Icon changes silently in the background (no alert on iOS).<br>- `false`: Immediate change, with system alert on iOS. |
#### β
Returns:
- `"DEFAULT"` if reset to the original icon.
- The **new icon name** on success.
- `false` if an error occurs.
---
### **Get Current Icon**
```typescript
import { getAppIcon } from "@howincodes/expo-dynamic-app-icon";
// Get the current app icon name
const icon = getAppIcon();
console.log(icon); // "red" (or "DEFAULT" if not changed)
```
---
- **Android limitations:**
Android does **not** support icon changes while the app is running in the foreground.
To work around this, the icon is changed when the app enters the **Pause state** (background).
- β οΈ **Pause state** can also trigger during events like permission dialogs.
To avoid unwanted icon changes, a **5-second delay** is added to ensure the app is truly in the background.
- To disable the delay and apply the icon change immediately (with the risk of it running during permission dialogs or other pause events), set:
```typescript
setAppIcon("red", false);
```
- On **iOS**, `isInBackground: false` triggers the system alert immediately.
- On **Android**, it applies the icon change right away without waiting.
A huge shoutout to [outsung](https://github.com/outsung) for the original package! π
If you find this useful, consider **buying him a coffee**:
<a href="https://www.buymeacoffee.com/outsung" target="_blank">
<img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" height="41" width="174" />
</a>
---
This package is maintained by **[HowinCloud](https://howincloud.com/)** β delivering powerful cloud-based solutions for modern app development.
π₯ **Enjoy building dynamic and customizable apps with Expo!** π