I have some .svg icons locally that I'd like to use in my RN project.
An example is an .svg icon like this (opened in Chrome):
I'd like to display this file (as well as having control in specifying fill color for it) -- is there any way to do this in React Native?
(i've tried 'react-native-remote-svg' component but that doesn't give me any control over coloring)
Thanks!
Open up the project in your favorite editor and start by importing the Svg and Circle components from react-native-svg, as shown below. import Svg, { Circle } from 'react-native-svg'; The <Svg> component is a parent component that is needed to render any SVG shape.
You can't change the color of an image that way. If you load SVG as an image, you can't change how it is displayed using CSS or Javascript in the browser. If you want to change your SVG image, you have to load it using <object> , <iframe> or using <svg> inline.
Scalable Vector Graphic (SVG) is an image format that uses vector graphics to display the image you see. They are now popular among developers because they scale to any resolution.
You can use react-native-svg-transformer to import svgs in to your code. Once you've set that up, you'll be able to do:
import ProfileIcon from './images/profile.svg'
You can then use ProfileIcon as a component.
To control the colour, edit the svg file and change the fill or stroke attributes to "currentColor"
(so <polygon fill="currentColor" ...>
). You can then set the color
style on your svg element and it'll use that colour: <ProfileIcon style={{ color: '#f80' }}/>
I'm using react-native-svg 9.3.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With