Skip to content

🤖 Programmatically change the app icon in Expo.

Notifications You must be signed in to change notification settings

mozzius/expo-dynamic-app-icon

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mozzius/expo-dynamic-app-icon

Note

This is a fork of expo-dynamic-app-icon to support Expo SDK 51. It also includes:

  • support for resetting the icon to the default
  • round icon support
  • different icons for Android and iOS

Programmatically change the app icon in Expo.

Install

npx expo install @mozzius/expo-dynamic-app-icon

Set icon file

add plugins in app.json

 "plugins": [
      [
        "expo-dynamic-app-icon",
        {
          "red": { // icon name
            "ios": "./assets/ios_icon1.png", // icon path for ios
            "android": "./assets/android_icon1.png", // icon path for android
            "prerendered": true // for ios UIPrerenderedIcon option
          },
          "gray": {
            "android": "./assets/icon2.png", // android-only icon
          }
        }
      ]
    ]

Check AndroidManifest (for android)

expo prebuild

check added line AndroidManifest.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>
  ...

Create new expo-dev-client

create a new expo-dev-client and begin using expo-dynamic-app-icon

Use setAppIcon

  • if error, return false
  • else, return changed app icon name
  • pass null to reset app icon to default
import { setAppIcon } from "expo-dynamic-app-icon";

...

setAppIcon("red") // set icon 'assets/icon1.png'

Use getAppIcon

get current app icon name

  • default return is DEFAULT
import { getAppIcon } from "expo-dynamic-app-icon";

...

getAppIcon() // get current icon name 'red'

Buy outsung (original author) a coffee! I couldn't have done it without his work! 👇

Buy Me A Coffee

About

🤖 Programmatically change the app icon in Expo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 65.8%
  • Kotlin 18.0%
  • JavaScript 8.8%
  • Swift 4.4%
  • Ruby 3.0%