React-native-svg: change fill for svg files

Created on 15 Apr 2020  路  3Comments  路  Source: react-native-svg/react-native-svg

hello, how can i change the fill of the paths dinamically, i am importing svg files with svg-transformer.

Most helpful comment

Hey @eladgel,
In your svg files, change the fill of all paths to currentColor.
settings.svg:

<svg fill="none" xmlns="http://www.w3.org/2000/svg"><path d="...." fill="currentColor" /></svg>

Then when you import them in your component, pass your desired color in the color prop:

import SettingIcon from '../assets/icons/settings.svg';

<SettingIcon color="blue" width={36} height={36} />

All 3 comments

looks like the path needs to have they currentColor keyword in its fill and then use the property color in the svg file component

@antonioreyna can you explain more or give an example, I have also encountered this issue

Hey @eladgel,
In your svg files, change the fill of all paths to currentColor.
settings.svg:

<svg fill="none" xmlns="http://www.w3.org/2000/svg"><path d="...." fill="currentColor" /></svg>

Then when you import them in your component, pass your desired color in the color prop:

import SettingIcon from '../assets/icons/settings.svg';

<SettingIcon color="blue" width={36} height={36} />
Was this page helpful?
0 / 5 - 0 ratings