How to show SVG file on React Native?

后端 未结 13 1572
被撕碎了的回忆
被撕碎了的回忆 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 12:02

    I use these two plugins,

    1. [react-native-svg] https://github.com/react-native-community/react-native-svg)
    2. [ react-native-svg-transformer] https://github.com/kristerkari/react-native-svg-transformer)

    First off all, You need to install that plugin. After that you need to change your metro.config.js, with this code.

    const { getDefaultConfig } = require("metro-config");
    
    module.exports = (async () => {
      const {
        resolver: { sourceExts, assetExts }
      } = await getDefaultConfig();
      return {
        transformer: {
          babelTransformerPath: require.resolve("react-native-svg-transformer")
        },
        resolver: {
          assetExts: assetExts.filter(ext => ext !== "svg"),
          sourceExts: [...sourceExts, "svg"]
        }
      };
    })();
    

    For more details, you can visit this link

    • https://medium.com/game-development-stuff/how-to-import-svgs-on-react-native-dc76b56403ba
    • https://medium.com/@majirosstefan/the-svgs-inside-react-native-0-61-5-and-storybook-566bcd43ba94
    0 讨论(0)
提交回复
热议问题