npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-dynamic-app-icon

v0.6.1

Published

Programmatically change the React Native app icon

Downloads

250

Readme

rn-dynamic-app-icon

Android/ iOS/ React

Programmatically change the app icon in React Native for both android and iOS.

  • Add icons to native projects
  • Config AndroidManifest.xml and Info.plist
  • ✨Magic ✨

| iOS |Android/ Android | | :--- | :----: | |iOS App sample|Android App sample|

Installation

  1. Adding package

NPM:

npm install rn-dynamic-app-icon

YARN:

yarn add rn-dynamic-app-icon
  1. iOS specific installation
cd ios && pod install

Setup

1. Android

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

Android Project sample

  1. Add the alternate icons in the AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.rndynamicappicon">
  <uses-permission android:name="android.permission.INTERNET" />
  
  <application
    android:name=".MainApplication"
    android:allowBackup="false"
    android:icon="@mipmap/sd"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/sd_round"
    android:theme="@style/AppTheme">
    <activity
      android:name=".MainActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
      android:label="@string/app_name"
      android:launchMode="singleTask"
      android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <activity-alias
      android:name=".MainActivityAU"
      android:enabled="false"
      android:icon="@mipmap/au"
      android:roundIcon="@mipmap/au_round"
      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=".MainActivityCA"
      android:enabled="false"
      android:icon="@mipmap/ca"
      android:roundIcon="@mipmap/ca_round"
      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=".MainActivityUK"
      android:enabled="false"
      android:icon="@mipmap/uk"
      android:roundIcon="@mipmap/uk_round"
      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=".MainActivityUS"
      android:enabled="false"
      android:icon="@mipmap/us"
      android:roundIcon="@mipmap/us_round"
      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>

The main point is to create tags to make more alternate icons. While the tag name should be your applications initial Activity name suffixed by you icon definition name example: .MainActivityAU NOTE: Default icon will have the initial Activity's name, example: .MainActivity


2. iOS

  1. Open you project in XCode and create a new group with folder and add you icons there, see image below:

iOS, Create New Group with Folder selection

  1. Include alternate icons by selecting add files option, which supports [email protected] format, see image below:

iOS, Add files to you project selection

  1. Add default icon set to Images.xcassets folder, now project structure should be as the image below:

iOS project structure

  1. Now all you need to do is configure Info.plist, follow the example below, make sure you are setting the icon name Exactly as the file name (without "@2x.png)
<key>CFBundleIcons</key>
<dict>
	<key>CFBundleAlternateIcons</key>
	<dict>
		<key>AU</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>AU</string>
			</array>
		</dict>
		<key>CA</key>
		<dict>
		    <key>CFBundleIconFiles</key>
			<array>
				<string>CA</string>
			</array>
		</dict>
		<key>UK</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>UK</string>
			</array>
		</dict>
		<key>US</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>US</string>
			</array>
		</dict>
	</dict>
</dict>

Now the Info.plist file should look as follows: info.plist structure

Usage

import {
    changeIcon, 
    WhenToKillOldClasses, //Optional: import this only if you need it
} from 'rn-dynamic-app-icon';

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

// Pass an empty string to enable default icon
changeIcon('');

// Android ONLY (OPTIONAL)
// extraParams object to customize the icon change behavior
//  1. customPackage
// Usage: to pass a custom launcher activity name: 
changeIcon('AU', {customPackageName: activityName});
//  2. whenToKillOldClasses
// Usage: define when to kill old icon class
/**  Available options:
    - WhenToKillOldClasses.ON_ACTIVITY_PAUSED (Default)
    - WhenToKillOldClasses.ON_ACTIVITY_STOPPED
    - WhenToKillOldClasses.ON_ACTIVITY_DESTROYED
*/
changeIcon('UK', {whenToKillOldClasses: WhenToKillOldClasses.ON_ACTIVITY_DESTROYED});

Special thanks

To @skb1129 for his work on a similar project which inspired me to implement this package with a bit of enhancements on both android and ios

To freepik, since all of the icons used in this projects are made by https://www.freepik.com