Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render svg image in React-Native?

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.

like image 380
Kunvar Singh Avatar asked Nov 28 '19 03:11

Kunvar Singh


People also ask

How render SVG react-native?

Rendering SVG shapes in React Native Open up the project in your favorite editor and start by importing the Svg and Circle components from react-native-svg, as shown below. import Svg, { Circle } from 'react-native-svg'; The <Svg> component is a parent component that is needed to render any SVG shape.

Can we use SVG image in react-native?

Scalable Vector Graphic (SVG) is an image format that uses vector graphics to display the image you see. They are now popular among developers because they scale to any resolution.

How do I display SVG images in react?

There are a few ways to use an SVG in a React app: Use it as a regular image. Import it as a component via bundler magic (SVGR) Include it directly as JSX.

What is SVG in react-native?

SVG is a vector format that can scale to any size without losing its quality, and it can do this while having a comparatively low file size too. SVG is amazing like that and preferred implementation on React Native Platform.


1 Answers

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"
  />
);
like image 197
Vipul Avatar answered Oct 17 '22 13:10

Vipul