1.3.0 • Published 3 years ago
react-native-svg-cache v1.3.0
react-native-svg-cache
Render SVG images in React Native from an URL or a static file
URL SVG's are cached using react native's Async Storage.
Forked from 'react-native-svg-uri'. Merge with source code of 'react-native-fast-svg'.
Install library from npm
npm install react-native-svg-cache --save
Link library react-native-svg
react-native link react-native-svg
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 | |
fillAll | Boolean | Adds the fill color to the entire svg object | |
fillAll | Boolean | false | Adds the fill color to the entire svg object |
noCache | Booleean | false | will not cache this particular SVG if true |
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-cache';
const TestSvgUri = () => (
<View style={styles.container}>
<SvgUri
width="200"
height="200"
source={{uri:'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg'}}
/>
</View>
);
or a static file
<SvgUri width="200" height="200" source={require('./img/homer.svg')} />
This will render:
Testing
- Make sure you have installed dependencies with
npm i
- Run tests with
npm test
1.3.0
3 years ago