How to show SVG file on React Native?

后端 未结 13 1605
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 11:13

I want to show svg files (I have bunch of svg images) but the thing I couldn\'t find the way to show. I tried to use Image and Use componen

13条回答
  •  情深已故
    2020-12-12 11:41

    I posted another solution here Which is the best approach to insert an vector (svg) graph into a react native application, This approach use a vector font(from svg) instead a svg file. PS: Its works great in ios and android, and you also can change the color and size of your vector icon.

    If you want to insert a svg directly into your app, you can try a 3rd party library : react-native-svg. With more than 3k stars in github it's one of the best approach.

    • install:
      • npm i react-native-svg
      • npm i react-native-svg-uri
    • link the to native:
      • react-native link react-native-svg

    And here's a sample:

    import * as React from 'react';
    import SvgUri from 'react-native-svg-uri';
    import testSvg from './test.svg';
    export default () => (
      
    );
    

提交回复
热议问题