2

Environment info

React native info output:

"react": "16.8.6",
"react-native": "0.60.4"

Library version: 1.2.3

Steps To Reproduce

  1. Create a fresh project using react-native-cli.
  2. Bring in an SVG file into the src folder of the project (I downloaded and used the homer simpson image mentioned in the documentation of react-native-svg-uri for the test ).
  3. Import the svg as import MySVG from './mysvg.svg';
  4. Pass MySVG into svgXmlData property of SvgUri component

Expected behaviour

The image should render on screen

Reproducible sample code

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

import MySVG from './mysvg.svg';

const MyComponent = () => {
  return (
     <>
      <SvgUri
        svgXmlData={MySVG}
        width="25"
        height="25"
      />
    </>
  );
};

export default MyComponent;

Error Message

error message

Muljayan
  • 3,588
  • 10
  • 30
  • 54

2 Answers2

1

You can try this Direct Path Declaration

<SvgUri
        width="25"
        height="25"
        source={require('./mysvg.svg')} />
hong developer
  • 13,291
  • 4
  • 38
  • 68
0

If you have a svg file declared and not using an uri, I would recommend to use the react-native-svg project from the react-native-community (https://github.com/react-native-community/react-native-svg)

With this, you turn your svg file to a React Stateless Component (the translation is quite straightforward) and you can use it as a standard React component.

Steve Alves
  • 598
  • 5
  • 12