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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-vector-image

v0.6.0

Published

Native vector images generated from SVG

Readme

Tests npm

  • Faster render – ~5x faster than react-native-svg.
  • Smaller JS bundle = faster startup.
  • Native support for dark mode.
  • Web support for Expo.

Installation

yarn add react-native-vector-image

Android

Edit android/app/build.gradle to look like this (without the +):

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
+ apply from: "../../node_modules/react-native-vector-image/strip_svgs.gradle"

iOS

Open your project in Xcode, select the Build Phases tab, and edit the Bundle React Native code and images script to look like this (without the +):

set -e

WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"
+ ../node_modules/react-native-vector-image/strip_svgs.sh

Expo

After installing this npm package, add the config plugin to the plugins array of your app.json or app.config.js:

{
  "expo": {
    "plugins": ["react-native-vector-image"]
  }
}

Next, rebuild your app as described in the "Adding custom native code" guide.

Options

{
  "expo": {
    "plugins": [
      [
        "react-native-vector-image",
        {
          // These are default options, change if you want a different value:
          "stripSvgs": false, // if true, svgs will be removed from bundle. expo-updates package crashes when svgs it expects in the bundle are not there
          "metroConfigFile": "metro.config.js",
          "resetCache": false,
          "bundleWithExpo": true,
          "entryFile": "index.ts"
        }
      ]
    ]
  }
}

Shout out to zamplyy for making the first version of the Expo plugin.

Usage

Since native vector assets cannot be served over http via metro dev server, they must be generated and compiled into the app bundle.

Step 1: import an .svg file

import VectorImage from 'react-native-vector-image';

const App = () => <VectorImage source={require('./image.svg')} />;

To add dark mode to your image, create a new file with an .dark.svg extension, ie image.svg = light and image.dark.svg = dark.

Step 2: generate native assets

This takes a while as metro has to go through all the code to find the imported SVGs.

Note: for Expo just use the plugin and npx expo prebuild.

yarn react-native-vector-image generate

| Argument | Description | Default | | ---------------------- | -------------------------------------------------------------------- | ----------------------------- | | --entry-file | Path to the app entrypoint file. | index.js | | --config | Path to the metro config file. | metro.config.js | | --reset-cache | Reset metro cache before extracting SVG assets. | false | | --bundle-with-expo | Whether to bundle the app with Expo presets or using metro directly. | false | | --ios-output | Path to an iOS .xcassets folder. | ios/AppName/Images.xcassets | | --no-ios-output | Disable iOS output. | false | | --android-output | Path to an Android res folder. | android/app/src/main/res | | --no-android-output | Disable Android output. | false | | --current-color | Replace any currentColor color references in SVGs. | #000000 | | --current-color-dark | Replace any currentColor color references in .dark.svg SVGs. | #ffffff |

Step 3: recompile

yarn react-native run-ios
# or
yarn react-native run-android

Optional: using source/drawable

If you need to use the underlying image source/drawable you can use the VectorImage.resolveAssetSource method, for example with Expo's native tabs:

const iconSource = VectorImage.resolveAssetSource(require('./icon.svg'));

return (
  <NativeTabs.Trigger name="index">
    <Icon src={iconSource} drawable={iconSource.uri} />
  </NativeTabs.Trigger>
);

Troubleshooting

generate command outputs "Error while parsing image.svg"

Some optimizations applied by SVGO are not compatible with the SVG parser on Android. Try to re-export the SVG without optimizing it.

<VectorImage /> warns "Could not find image"

It means that the native vector asset does not exist or is out of sync with the SVG. Simply generate the files and recompile the app.

the generate command does not generate any new assets

Make sure your image component is used (imported) somewhere in your code, otherwise the asset generator won't find it.

License

MIT License. © Joel Arvidsson 2021

svg2vd: MIT © 2020 Shopify