1

We are working on a Vue/ReactNative project and have the strange phenomenon that in the Reactnative component react-native-svg (version 12.1.0) the SVG is not rendered correctly. In the browser it is rendered correctly.

The SVG itself was created with Adobe and uses CSS styles. Are not all CSS elements supported ?

We use the SVGs dynamically from an external Uri and not as a static file.

<svg-css-uri
    :key="'image_' + selectedItem.id"
    :height="200"
    :uri="selectedItem.picture.url"
  ></svg-css-uri>
</view>
    
    
mystyle: {
  marginLeft: 25,
  flex: 0.5,
  justifyContent: "center",
}

should like this

enter image description here

looks like this (wrong)

enter image description here

pbachman
  • 934
  • 2
  • 11
  • 18

2 Answers2

3

There are 2 ways to use SVG images using react-native-svg

1. Converting to react components

You can convert your svg image to react components by using this playground.

Note: there is also a possibility to convert the image via CLI but I prefer playground as it is easier.

2. Using SVG files directly

For this, you might want to flow the steps mentioned in the docs here

Marmik Thakkar
  • 108
  • 1
  • 6
  • We use the SVGs dynamically from an external Uri, did I understand it correctly that we can use "react-native-svg-transformer" for our case ? – pbachman Mar 25 '21 at 06:03
  • 1
    May be you should try this inside `.svgrrc` https://github.com/kristerkari/react-native-svg-transformer/issues/11#issuecomment-484056625 – Marmik Thakkar Mar 25 '21 at 09:35
2

I was able to render the SVG on iOS under React Native as follows: https://www.codepile.net/pile/7AP5vlmn (use this code)

Using https://react-svgr.com/playground/, I converted the SVG into a React Native component. You can then easily import and render from a .js file. This is how it looks on the iOS Simulator:

enter image description here

Arbnor
  • 2,190
  • 18
  • 26
  • 1
    We use the SVGs dynamically from an external Uri, we don't use it as a static asset. is there way to do it on-the-fly ? – pbachman Mar 25 '21 at 06:05