我想显示 svg 文件(我有一堆 svg 图像),但我找不到显示的方式。我尝试使用Image and Use的组成部分反应本机 svg https://github.com/magicismight/react-native-svg但他们不这样做。我尝试用原生方式做到这一点,但仅显示 svg 图像确实很困难。
示例代码:
import Svg, {
Use,
Image,
} from 'react-native-svg';
<View>
<Svg width="80" height="80">
<Image href={require('./svg/1f604.svg')} />
</SvgRn>
</View>
我也知道 React Native 基本上不支持 svg 但我认为有人用棘手的方式解决了这个问题(有/没有react-native-svg)
我使用了以下解决方案:
- Convert
.svg
图像到 JSXhttps://svg2jsx.herokuapp.com/ https://svg2jsx.herokuapp.com/
- 将 JSX 转换为
react-native-svg
组件与https://react-svgr.com/playground/?native=true https://react-svgr.com/playground/?native=true(确保选中“React Native”复选框)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)