Skip to content

moduate/react-native-svg-app-icon

 
 

Repository files navigation

react-native-svg-app-icon

Android adaptive icon iOS icon Android legacy square icon Android legacy round icon

Build Status

CLI tool for generating all the necessary iOS and Android application launcher icons for React Native projects from a single SVG source file. Features include:

  • iOS PNG icon generation
  • Android 8.0, and higher, vector drawable adaptive icon generation with PNG fallback
  • Android 7.1 legacy circular icon generation
  • Android 7.0, and lower, legacy square icon generation

For more information about the generated files, see the docs.

➰ If you also want to use SVG images within your React Native application, you might want to check out react-native-svg-asset-plugin.

Installation

npm install --save-dev react-native-svg-app-icon

SVG rendering handled by the splendid sharp library, meaning no dependencies outside of npm is required.

Requires node version 10, or later.

Usage

Place your square 108x108 SVG app icon file named icon.svg in the project root and run

npx react-native-svg-app-icon

This will generate all the required icons under the android/ and ios/ directories.

Icon format

The input icon should be a SVG file adhering to the Android adaptive icon specification. Specifically, the image should:

  • Be a valid SVG image
  • have a 1:1 aspect ratio
  • Have a size of 108x108dp

of which the:

  • Center 72x72dp square is the normally visible area
  • Center 66dp diameter circle is the safe area which will always be visible

With the various icons cropped according to the following image

Icon copping anatomy

  • #444 Overflow area
  • #666 Visible area
  • #888 iOS / Android legacy square crop
  • #AAA Android legacy circular crop
  • #CCC Safe area
  • #F00 Icon keylines

For an example icon file, see example/icon.svg.

Rationale

React Native aims to provide tools for building cross platform native mobile applications using technologies familiar from web development. Since the core tooling doesn't provide a solution for building the laundher icons for those applications, this tool aims to fill that gap.

Luckily, most icons follow a similar structure of a foreground shape on a background, which is easily adapted to different shapes and sizes. This is the idea behind Android Adaptive Icons, and what the Android Image Asset Studio implements nicely for generating leagy icons. This tool can actually be though of as a NPM CLI port of the Image Asset Studio, with added support for generating iOS icons as well.

Other work

Most existing solutions are centered around the idea of scaling PNG images.

  • Expo: Scales PNG files generating the required iOS and Android variants, but requires users to supply platform specific PNGs in order to adhere to platform icon design guidelines.
  • app-icon: Similar to Expo, with some added features such as labeling the icons. Requires imagemagick.

Troubleshooting

Supported SVG features

Most common SVG features are supported, including masks and styles. The underlying SVG rendering library is librsvg which claims to support most SVG 1.1 features, excluding scripts, animations and SVG fonts.

Future improvements

About

Generate all app icons for you React Native apps from a single SVG file

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 63.5%
  • JavaScript 13.3%
  • Objective-C 11.0%
  • Ruby 6.0%
  • Java 4.6%
  • Python 1.6%