Search code examples
javascriptreactjsreact-nativesvgreact-native-svg

unable to implement local svg image in react-native app


I am uanble to implement png converted svg to my react-native application even after installing below libraries "react-native-svg": "false12.1.0", "react-native-svg-uri": "false1.2.3",

I am using latest react-native version and has followed all steps to implement provided by various forum on google still getting 'TypeError:json.stringify cannot serialize cyclic structures'

Please help me with the steps to implement local svg image file in the application


Solution

  • png converted SVG Icon

    const MY_ICON = `<?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
     "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    <svg version="1.0" xmlns="http://www.w3.org/2000/svg"
     width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
     preserveAspectRatio="xMidYMid meet">
    <metadata>
    Created by potrace 1.16, written by Peter Selinger 2001-2019
    </metadata>
    <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
    fill="#000000" stroke="none">
    <path d="M4830 4494 c-23 -10 -612 -592 -1718 -1697 l-1682 -1682 -553 552
    c-382 383 -563 557 -589 568 -79 32 -181 12 -234 -47 -53 -58 -71 -160 -40
    -231 8 -18 288 -305 662 -678 526 -524 656 -649 688 -659 59 -19 137 -7 188
    28 24 17 829 817 1790 1779 1244 1244 1752 1759 1763 1785 33 81 12 190 -47
    245 -54 51 -157 68 -228 37z"/>
    </g>
    </svg>
    `;
    

    Quick way to achieve is with the SvgXml component from react-native-svg.

    import {SvgXml} from 'react-native-svg';
    
    
    <SvgXml xml={MY_ICON} width={50} height={50} fill={'black'} />