react-native-trustee-change-icon

1.0.3 • Public • Published

React Native Trustee Change Icon

npm version

Change Application Icon Programmatically.

  • [x] iOS
  • [x] Android

Getting started

yarn i react-native-trustee-change-icon

Usage

iOS

  1. Open your project in Xcode and create an App Icons group inside you app's group.
  2. Add all the app icons you need inside this group with names like icon@2x.png, icon@3x.png.
  3. Your directory structure in Xcode would look like:

Xcode Directory

  1. Open the Info.plist file.
  2. Add Icon files (iOS 5) to the Information Property List.
  3. Add CFBundleAlternateIcons as a dictionary to the Icon files (iOS 5), it is used for alternative icons.
  4. Add dictionaries under CFBundleAlternateIcons named as your icon names in App Icons group.
  5. For each dictionary, two properties, UIPrerenderedIcon and CFBundleIconFiles need to be configured.
  6. Set the type of UIPrerenderedIcon to String and its value to NO.
  7. Set the type of CFBundleIconFiles to Array and set its first key, Item 0's type to String and its value to the corresponding icon names.
  8. After all these steps, your Info.plist file should look like:

Info.plist

Android

  1. Add all the icons you need inside your project's android/app/src/main/res/mipmap-* directories:

Android Directory

  1. Modify your AndroidManifest.xml file's <application> tag as following:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

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

	<application
		android:name=".MainApplication"
		android:label="@string/app_name"
		android:icon="@mipmap/checked"
		android:allowBackup="false"
		android:theme="@style/AppTheme">

		<activity android:name=".MainActivity" />

		<activity-alias
			android:name="com.example.MainActivitychecked"
			android:enabled="true"
			android:exported="true"
			android:icon="@mipmap/checked"
			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="com.example.MainActivitycancel"
			android:enabled="false"
			android:exported="true"
			android:icon="@mipmap/cancel"
			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>

You can create more <activity-alias> tags to make more alternate icons. Note that the name in should be "com.{package_name}.MainActivity%", where % is the icon name.

Note that all the icon names must be in lowercase and only limited to alphabets a-z

Now you can use the following code to change application icon:

import { changeIcon, getIcon } from 'react-native-trustee-change-icon';

// Pass the name of icon to be enabled
changeIcon('iconName');

// Get the icon currently enabled
getIcon();

changeIcon function returns a Promise<string>. The promise is resolved only when the icon is changed.

getIcon function returns Promise<string> with the name of the selected icon or "default" if default icon is selected.

Please refer to the example app for demo on implementation

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.317latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.317
1.0.21
1.0.11
1.0.01

Package Sidebar

Install

npm i react-native-trustee-change-icon

Weekly Downloads

20

Version

1.0.3

License

MIT

Unpacked Size

1.2 MB

Total Files

35

Last publish

Collaborators

  • shchipskii_yura