All Projects → oblador → react-native-vector-image

oblador / react-native-vector-image

Licence: MIT license
iOS/Android native vector assets generated from SVG

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
objective c
16641 projects - #2 most used programming language
Starlark
911 projects
shell
77523 projects
ruby
36898 projects - #4 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to react-native-vector-image

React Native Simple Modal
A simple JavaScript modal component for React Native.
Stars: ✭ 179 (-20.09%)
Mutual labels:  react-native-component
svg-non-stop
SVG import "Gradient has no stop info" fix
Stars: ✭ 65 (-70.98%)
Mutual labels:  vector-drawable
Animatedsvgview
Animated SVG Drawing for Android
Stars: ✭ 1,927 (+760.27%)
Mutual labels:  vector-drawable
React Native Side Menu
Side menu component for React Native
Stars: ✭ 2,214 (+888.39%)
Mutual labels:  react-native-component
React Native Hero
🤘 A super duper easy hero unit react-native component with support for dynamic image, dynamic sizing, color overlays, and more
Stars: ✭ 234 (+4.46%)
Mutual labels:  react-native-component
svg2vector
Online batch converter of SVG images to Android vector drawable XML resource files
Stars: ✭ 39 (-82.59%)
Mutual labels:  vector-drawable
React Native Timeline Flatlist
FlatList based timeline component for React Native for iOS and Android
Stars: ✭ 163 (-27.23%)
Mutual labels:  react-native-component
react-native-component-splitter
VS Code Extension allows splitting React Native Component into Sub-Component
Stars: ✭ 33 (-85.27%)
Mutual labels:  react-native-component
React Native Responsive Dimensions
Resposive fontSize, height and width for react-native components, that automatically adjusts itself based on screen-size of the device.
Stars: ✭ 243 (+8.48%)
Mutual labels:  react-native-component
Vectormaster
Dynamic control over vector drawables!
Stars: ✭ 1,540 (+587.5%)
Mutual labels:  vector-drawable
React Native Beautiful Video Recorder
The video recorder component that extends from react-native-camera. It works for both iOS & Android.
Stars: ✭ 204 (-8.93%)
Mutual labels:  react-native-component
React Native Dynamic Search Bar
Medium Article: https://freakycoder.com/react-native-library-dynamic-search-bar-c03fea9fae36
Stars: ✭ 225 (+0.45%)
Mutual labels:  react-native-component
easy-animated-vector-drawable
A library that helps using Animated Vector Drawables.
Stars: ✭ 40 (-82.14%)
Mutual labels:  vector-drawable
React Native Photos Framework
A modern and comprehensive CameraRoll/iCloud-library-API for React Native 📸 📹
Stars: ✭ 190 (-15.18%)
Mutual labels:  react-native-component
Richpath
💪 Rich Android Path. 🤡 Draw as you want. 🎉 Animate much as you can.
Stars: ✭ 2,259 (+908.48%)
Mutual labels:  vector-drawable
React Native Performance Monitor
React Native Performance Monitor - Realtime graphing of React Native render performance
Stars: ✭ 174 (-22.32%)
Mutual labels:  react-native-component
AnimatedVectorDrawableCompat-play-to-reset-button
An Android app using the AnimatedVectorDrawable support library
Stars: ✭ 56 (-75%)
Mutual labels:  vector-drawable
react-native-android-notification-listener
React Native Android Notification Listener - Listen for status bar notifications from all applications
Stars: ✭ 87 (-61.16%)
Mutual labels:  react-native-component
react-native-touchable
React-Native button helper library
Stars: ✭ 46 (-79.46%)
Mutual labels:  react-native-component
PaintCode2Skia
Convert your PaintCode app drawings (Android java export) to SkiaSharp C# code
Stars: ✭ 39 (-82.59%)
Mutual labels:  vector-drawable

React Native Vector Image

iOS/Android native vector assets generated from SVG.

Tests npm

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

Installation

yarn add react-native-vector-image @klarna/react-native-vector-drawable

Android

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

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
+ 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

export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
+ ../node_modules/react-native-vector-image/strip_svgs.sh

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.

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
--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

Step 3: recompile

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].