@datacamp/react-native-svg-uri
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

react-native-svg-uri

Render SVG images in React Native from an URL or a static file

This was tested with RN 0.33 and react-native-svg 4.3.1 (depends on this library) react-native-svg

Not all the svgs can be rendered, if you find problems fill an issue or a PR in order to contemplate all the cases

Install library from npm

npm install @datacamp/react-native-svg-uri --save

Link library react-native-svg

react-native link react-native-svg # not react-native-svg-uri !!!

Props

Prop Type Default Note
source ImageSource Same kind of source prop that <Image /> component has
svgXmlData String You can pass the SVG as String directly
fill Color Overrides all fill attributes of the svg file
classes Object Overrides attributes of classes, only those attributes present in the given object

Known Bugs

  • [ANDROID] There is a problem with static SVG file on Android, Works OK in debug mode but fails to load the file in release mode. At the moment the only workaround is to pass the svg content in the svgXmlData prop.

Usage

Here's a simple example:

import SvgUri from 'react-native-svg-uri';

const TestSvgUri = () => (
  <View style={styles.container}>
    <SvgUri
      width="200"
      height="200"
      source={{uri:'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg'}}
      classes={{'cls-1': {strokeWidth: 5}}}
    />
  </View>
);

or a static file

<SvgUri width="200" height="200" source={require('./img/homer.svg')} />

This will render:

Component example

Testing

  1. Make sure you have installed dependencies with npm i
  2. Run tests with npm test

Package Sidebar

Install

npm i @datacamp/react-native-svg-uri

Weekly Downloads

6

Version

1.2.4

License

ISC

Last publish

Collaborators

  • dejakob
  • carlos.braz
  • timwillaert
  • stereopt
  • alancowesdc
  • ubmit
  • lukasvermeiredatacamp
  • lazzystep
  • diegomachado-datacamp
  • peter.buschenreiter
  • victor-vansteenkiste
  • matarolangeraert
  • rplopes
  • yorandatacamp
  • larisa-datacamp
  • mmartinsdc
  • dextro
  • acmpires
  • jessestell
  • almeida-datacamp
  • wilant
  • patryk.szulczyk
  • martinchio
  • dc-eriktisme
  • ruiguedes
  • olivierkamers
  • gui.cabral
  • datacamp-machine-user
  • tomaszwisniewski
  • alanhughesdatacamp
  • datacamp-paulomonteiro
  • marcinnaglik
  • zpieslak
  • vvankrunkelsven
  • evertet
  • marbdq-dc
  • mzetea
  • frederikvg
  • nhlongnguyen
  • cdalby
  • luigi-dintrono-dc
  • eoliveiradc
  • berndschrooten
  • _bogdan_floris_
  • denathoxhadc
  • smidge
  • joachimzeelmaekers
  • garyalway
  • jdmunro
  • close-d-dev
  • herve-eerebout
  • dandenney
  • ewaldbervoets
  • rikbw
  • abordanpeter
  • aarondc
  • hermansje
  • nunorafaelrocha
  • timsangster
  • tuur
  • lipsumar
  • caterina
  • chrisramakers
  • ppetermann
  • springerigor
  • louiejakebell
  • kogitoja
  • samwooler
  • forvalho
  • bruno.datacamp
  • marcin-data
  • julienbenaouda