React Native display SVG from a file

前端 未结 3 1503
执念已碎
执念已碎 2020-12-17 18:19

How do I display an SVG image that I require() in React Native.

  • https://github.com/brentvatne/react-native-svgkit Is not under active development
3条回答
  •  盖世英雄少女心
    2020-12-17 18:53

    You can hack around this using a webview. I also had to put my SVGs as strings in .js files (which is not good at all). But it works pretty reliably. There is a split second where they show up as white before the SVG loads, but it's good enough for me.

    Roughly something like:

    import React, { View, WebView } from 'react-native'
    import s from 'string'
    
    const firstHtml = ''
    const lastHtml = ''
    export default (props) =>
      
        
      
    

提交回复
热议问题