SVG 在 React Native 项目中的使用 [英] SVG use in React Native project

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

问题描述

我想在我的 React Native 项目中使用 SVG 图标.我要求它像:

I want to use SVG icons in my React Native project. I'm requiring it like:

var svg = require('../images/Upvote.svg');

但我收到此错误:

无法从以下位置解析模块 ../images/Upvote.svg/path/to/my/project/js/Component.js:无效目录/path/to/my/project/images/Upvote.svg

Unable to resolve module ../images/Upvote.svg from /path/to/my/project/js/Component.js: Invalid directory /path/to/my/project/images/Upvote.svg

我是否想在 Xcode 项目设置中添加/更改某些内容?

Am i suppose to add/change something in Xcode project settings?

顺便说一句,如果我使用的是 PNG 图像,一切都很好,没有错误..

BTW, everything is fine if i'm using PNG image, no errors..

推荐答案

此时 React Native 不支持 SVG.有一些库他们玩过这个想法,但我不知道它们中的任何一个是生产就绪"

SVGs are not supported in React Native at this point. There are a few libraries out there they played with the idea but I don't know that any of them are "production ready"

https://github.com/brentvatne/react-native-svg

https://github.com/aksonov/react-native-svg-elements

这篇关于SVG 在 React Native 项目中的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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