如何在React-native或Expo中使用SVG-Uri? [英] How to use SVG-Uri in React-native or Expo?

查看:116
本文介绍了如何在React-native或Expo中使用SVG-Uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了 expo-svg-uri模块以使用Svg图像.

I downloaded the expo-svg-uri module to use the Svg image.

但是图像显示不正确.

代码我失败了:

  <View style={styles.container}>
    <SvgUri
      width="200"
      height="200"
      source={require("../../image/minigroup.svg")}
    />
  </View>

图片失败

原始图片

这是我的svgfile

this is my svgfile

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="80" height="183" viewBox="0 0 80 183">
    <defs>
        <circle id="b" cx="35" cy="35" r="35"/>
        <filter id="a" width="142.9%" height="142.9%" x="-21.4%" y="-21.4%" filterUnits="objectBoundingBox">
            <feOffset in="SourceAlpha" result="shadowOffsetOuter1"/>
            <feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5"/>
            <feColorMatrix in="shadowBlurOuter1" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0"/>
        </filter>
        <circle id="d" cx="35" cy="34" r="24"/>
        <filter id="c" width="168.8%" height="168.8%" x="-28.1%" y="-28.1%" filterUnits="objectBoundingBox">
            <feOffset dx="3" dy="3" in="SourceAlpha" result="shadowOffsetOuter1"/>
            <feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5"/>
            <feColorMatrix in="shadowBlurOuter1" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0"/>
        </filter>
        <circle id="f" cx="35" cy="34" r="12"/>
        <filter id="e" width="208.3%" height="208.3%" x="-45.8%" y="-45.8%" filterUnits="objectBoundingBox">
            <feOffset dx="2" dy="2" in="SourceAlpha" result="shadowOffsetOuter1"/>
            <feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="4"/>
            <feColorMatrix in="shadowBlurOuter1" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0"/>
        </filter>
    </defs>
    <g fill="none" fill-rule="evenodd">
        <text fill="#646464" font-family="Bungee-Regular, Bungee" font-size="20" letter-spacing="-.375">
            <tspan x="6.107" y="163">Point</tspan>
        </text>
        <text fill="#3D3D3D" font-family="Bungee-Regular, Bungee" font-size="20" letter-spacing="-.375">
            <tspan x="20.282" y="140">Tap</tspan>
        </text>
        <g transform="translate(5 5)">
            <rect width="70" height="81" y="28" fill="#FFD90D" rx="12"/>
            <use fill="#000" filter="url(#a)" xlink:href="#b"/>
            <use fill="#FFD90D" xlink:href="#b"/>
            <use fill="#000" filter="url(#c)" xlink:href="#d"/>
            <use fill="#FFD90D" xlink:href="#d"/>
            <g>
                <use fill="#000" filter="url(#e)" xlink:href="#f"/>
                <use fill="#FFD90D" xlink:href="#f"/>
            </g>
        </g>
    </g>
</svg>

我没有路径值,我只绘制了所有内容.你是说这有可能吗?

I don't have a path value, I'm only drawing it all. Are you saying this is possible?

请帮助我们很多.预先谢谢你.

Please help us a lot. Thank you in advance.

推荐答案

第一

  • 将您的svg文件拖放到此在线工具中 SVGOMG
  • 切换到标记"标签.
  • 复制path xml标记的d属性.
  • Drag your svg file into this online tool SVGOMG
  • Switch to the Markup tab.
  • Copy d attribute of the path xml tag.

第二

  • Render your svg file directly using react-native-svg

react-native-svg已安装并链接

将显示主页"图标的示例:

Example that would render Home icon:

<Svg
  width="20"
  height="20"
  viewBox="0 0 512 512" // Has to be the same of the original svg file
>
  <Path
    d="M208 448V320h96v128h97.6V256H464L256 64 48 256h62.4v192z"
    fill="red"
  />
</Svg>

这将为您节省加载和读取文件的成本...

This 'd save you as well the cost of loading and reading file ...

这篇关于如何在React-native或Expo中使用SVG-Uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆