@computools/react-native-dynamic-app-icon

中文文档
1.0.1发布于 2025/01/21MITTypeScriptESM + CJS零依赖近 30 天下载 4500

Dynamically change the app icon in React Native with cross-platform support for iOS and Android. Perfect for themes, events, and personalization.

原始使用文档
文档目录12 节
  1. Installation
  2. iOS Set Up
  3. Generate App Icons
  4. App Icons Set Up
  5. Android
  6. iOS
  7. Methods
  8. Usage
  9. Change Icon
  10. Get Icon
  11. Contributing
  12. License

@computools/react-native-dynamic-app-icon 🚀

Dynamically change the app icon in React Native with cross-platform support for iOS and Android. Perfect for themes, events, and personalization.

iOS Android

Installation

Using Yarn

yarn add @computools/react-native-dynamic-app-icon

Using npm

npm i @computools/react-native-dynamic-app-icon

iOS Set Up

After installing the package, run:

cd ios
pod install

Generate App Icons

Generate app icons using a tool like appicon.co to ensure all required sizes and formats are included.

App Icons Set Up

Android

Step 1: Add App Icons Files

  1. Rename generated files to ic_launcher_<icon_type>.png e.g. ic_launcher_orange.png.
  2. Rename default icon files to to ic_launcher_default.png
  3. Move app icons files to android/app/src/main/res/mipmap-*.

Step 2: Modify AndroidManifest.xml

  1. Add activity-alias for each icon.
<activity-alias
  android:name=".MainActivityPineapple" // .MainActivity + <icon-type>
  android:enabled="false"
  android:exported="true"
  android:icon="@mipmap/ic_launcher_pineapple"
  android:targetActivity=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity-alias>

Important: android:enabled="true" should be only for default activity-alias, other should have android:enabled="false".

  1. Remove <category android:name="android.intent.category.LAUNCHER" /> for activity-alias with android:enabled="true".

Notes:

  1. Don’t forget to use the correct file for android:icon and android:name. android:name is .MainActivity + e.g for android:icon=ic_launcher_orange android:name=".MainActivityOrange".
  2. Don't forget to change android:icon to "@mipmap/ic_launcher_default" in <application> tag.
  3. Make sure you have activity-alias with android:icon=ic_launcher_default, android:name=".MainActivityDefault".

AndroidManifest.xml example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <uses-permission android:name="android.permission.INTERNET" />

  <application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher_default"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">
    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
      android:launchMode="singleTask"
      android:windowSoftInputMode="adjustResize"
      android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity-alias
      android:name=".MainActivityDefault"
      android:enabled="true"
      android:exported="true"
      android:icon="@mipmap/ic_launcher_default"
      android:targetActivity=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
      </intent-filter>
    </activity-alias>
    <activity-alias
      android:name=".MainActivityPineapple"
      android:enabled="false"
      android:exported="true"
      android:icon="@mipmap/ic_launcher_pineapple"
      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=".MainActivityStrawberry"
      android:enabled="false"
      android:exported="true"
      android:icon="@mipmap/ic_launcher_strawberry"
      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=".MainActivityOrange"
      android:enabled="false"
      android:exported="true"
      android:icon="@mipmap/ic_launcher_orange"
      android:targetActivity=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity-alias>
  </application>
</manifest>

iOS

Step 1: Add App Icons Files

  1. Rename generated AppIcon.appiconset folders to <icon-type>Icon.appiconset.
  2. Rename default AppIcon.appiconset to DefaultIcon.appiconset.
  3. Move all .appiconset folders into ios/<app-name>/Images.xcassets.
  4. Update folder values in each Contents.json file e.g "folder": "Images.xcassets/PineappleIcon.appiconset/".

Step 2: Set up App Icon in Xcode

  1. Open Xcode;
  2. Go to app's General settings;
  3. Scroll to App Icons and Launch Screen;
  4. Set App Icon to DefaultIcon and check the Include all app icon assets checkbox below.

Step 3: Modify Info.plist

  1. Open Xcode, go to Info and insert a key for CFBundleIcons.
  2. Within CFBundleIcons dictionary add key CFBundleAlternateIcons.
  3. Within CFBundleAlternateIcons add keys for alternative icons:
  • The key is the name you will reference from within code.
  • Set the first array item to the name of the target .appiconset.
  1. Within CFBundleIcons set the default icon name in CFBundlePrimaryIcon and UINewsstandIcon -> Icon files -> Item 0.

Info.plist example:

<key>CFBundleIcons</key>
<dict>
  <key>CFBundleAlternateIcons</key>
  <dict>
    <key>DefaultIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>DefaultIcon</string>
      </array>
      <key>UIPrerenderedIcon</key>
      <false/>
    </dict>
    <key>OrangeIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>OrangeIcon</string>
      </array>
      <key>UIPrerenderedIcon</key>
      <false/>
    </dict>
    <key>PineappleIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>PineappleIcon</string>
      </array>
      <key>UIPrerenderedIcon</key>
      <false/>
    </dict>
    <key>StrawberryIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>StrawberryIcon</string>
      </array>
      <key>UIPrerenderedIcon</key>
      <false/>
    </dict>
  </dict>
  <key>CFBundlePrimaryIcon</key>
  <dict>
    <key>CFBundleIconFiles</key>
    <array>
      <string>DefaultIcon</string>
    </array>
    <key>CFBundleIconName</key>
    <string></string>
    <key>UIPrerenderedIcon</key>
    <false/>
  </dict>
  <key>UINewsstandIcon</key>
  <dict>
    <key>CFBundleIconFiles</key>
    <array>
      <string>DefaultIcon</string>
    </array>
    <key>UINewsstandBindingEdge</key>
    <string>UINewsstandBindingEdgeLeft</string>
    <key>UINewsstandBindingType</key>
    <string>UINewsstandBindingTypeMagazine</string>
  </dict>
</dict>

Methods

MethodDescriptionParametersReturns
changeIcon<T extends string>(iconName: T)Changes the app's icon to the specified icon.
Note: The package automatically closes the app on Android after changing the app icon. This behavior is implemented to prevent duplicate icons and requires no additional action from the user.
iconName (T): The name of the icon to switch to.Promise<void>: Resolves with void or rejects with an error.
getIcon<T extends string>()Retrieves the name of the currently active app icon.NonePromise<T>: Resolves with the name of the current used icon or rejects with an error.

Usage

Change Icon

import { changeIcon } from '@computools/react-native-dynamic-app-icon';

const setAppIcon = async () => {
  try {
    await changeIcon('Orange');
  } catch (error) {
    // error handling
  }
}

setAppIcon();

Get Icon

import { getIcon } from '@computools/react-native-dynamic-app-icon';

const getCurrentIcon = async () => {
  try {
    const currentIcon = await getIcon();
    // the logic of saving the currentIcon or other
  } catch (error) {
    // error handling
  }
}

getCurrentIcon();

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

版本与发布记录

@computools/react-native-dynamic-app-icon 共发布 2 个版本,首次发布于 2025/01/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2025/01/211.8 年前
1.0.02025/01/211.8 年前

关于 @computools/react-native-dynamic-app-icon 的常见问题

@computools/react-native-dynamic-app-icon 是什么?

Dynamically change the app icon in React Native with cross-platform support for iOS and Android. Perfect for themes, events, and personalization.

如何安装 @computools/react-native-dynamic-app-icon?

在项目目录运行 npm install @computools/react-native-dynamic-app-icon,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@computools/react-native-dynamic-app-icon 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@computools/react-native-dynamic-app-icon 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@computools/react-native-dynamic-app-icon 可以商用吗?

@computools/react-native-dynamic-app-icon 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@computools/react-native-dynamic-app-icon 的下载量有多少?

根据 npm 官方下载统计,@computools/react-native-dynamic-app-icon 在 2026/10/11 – 2026/11/09 这 30 天内被下载 4,500 次,日均约 150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@computools/react-native-dynamic-app-icon 还在维护吗?

最新版本 1.0.1 发布于 2025/01/21(1.8 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/01/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。