Convert svg to react-native-svg

后端 未结 2 1802
耶瑟儿~
耶瑟儿~ 2021-02-05 16:42

What is the easiest way to do this? I found plenty of svg to JSX converters, which is what I want, but that doesn\'t work in react-native. I need to convert the svg code to some

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 17:13

    I'm using expo for building react native app and I had the same inquiry but I found some solution here react-native-svg. I use the XML Option which was as below.

    STEP 1- first I used this link convert SVG to JSX for React to convert the SVG to JSX (Some times you don't need to convert it, it depends on icon itself).

    STEP 2- open new file component and import react and import { SvgXml } from 'react-native-svg', then create a normal functional component inside.

    STEP 3- wrap the converted SVG icon tag with Quotation mark to be like this "some icon code inside" then store it in a variable var, const, let..etc.

    STEP 4- return .

    STEP 5- export the component as usual.

    here is an example code

    import React from 'react'
    import { SvgXml } from 'react-native-svg';
    
    function FastRunningIcon(props) {
        const xml = `
        
    `
    
        return 
    }
    
    export default FastRunningIcon;
    

提交回复
热议问题