8

Please try to help me! I need to render svg image from my folder "project/assest/images/test.svg" on android and ios view.

I have tried :

Solution 1 : <Image source={imagePath}></Image>

Solution 2 :

import SvgUri from 'react-native-svg-uri';
 <View>
    <SvgUri
      width="200"
      height="200"
      source={{uri:'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg'}}
    />
  </View>

Solution 3 : First i should, convert svg file to png,jpeg then render simple image, but that very weired way on view

Please help, what did i wrong in this.

3 Answers 3

10

You can also try react-native-svg package for SVG

For Example --

import * as React from 'react';
import { SvgUri } from 'react-native-svg';

export default () => (
  <SvgUri
    width="100%"
    height="100%"
    uri="http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg"
  />
);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I'll try this Happy coding!
Make sure to check out the docs of the above mentioned package react-native-svg. It offers basically any possible way to use an svg. You can also pass svg as string to one of the components it brings, which I wasn't aware and didn't find through search engines, just in the docs itself.
-1

You can try with this

<SvgUri width="200" height="200" source={require('./project/assest/images/test.svg')} />

May this will help you

1 Comment

If we are using image from url, then we directly assign uri. For image which is inside our folder we have to require in <Image tag also.
-2

here are two ways to use SVG in react-native.
one way is to translate the SVG to JSX use this site.
the other way is to use a font instead of SVG directly:

  1. firstly, use SVG files to generate font. I use this site. it is fontello.
  2. then I use react-native-vector-icons to generate icon. for more details, you can see its API

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.