Changing SVG fill color in JS Code -- need processColor() for IOS
See original GitHub issueFollowed the steps under https://github.com/kristerkari/react-native-svg-transformer#changing-svg-fill-color-in-js-code.
Called my svg element like so:
<Account width={100} height={100} color={'red'} />
Works fine in Android. SVG icon is red yay. Problem is in IOS I get this error: `JSON value of ‘red’ of type NSString cannot be converted to a UIColor. Did you forget to call processColor() on the JS side?
Changed to:
import {processColor} from 'react-native';
...
<Account width={100} height={100} color={processColor('red')} />
and then it worked in IOS, but causes issues in Android. Only way I can see to do it now is:
import {processColor, Platform} from 'react-native';
...
<Account width={100} height={100} color={Platform.OS === 'ios' ? processColor('red') : 'red'} />
Anyone experienced this or have a better idea of how to solve this? End of day tired and haven’t looked through this package source code to investigate further.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How can I change the color of an 'svg' element? - Stack Overflow
To change the color of any SVG, you can directly change the SVG code by opening the SVG file in any text editor....
Read more >Choose colors in Adobe Photoshop
To change the foreground color, click the upper color selection box in the toolbox, and then choose a color in the Adobe Color...
Read more >stop-color - SVG: Scalable Vector Graphics - MDN Web Docs
The stop-color attribute indicates what color to use at a gradient stop. Note: With respect to gradients, SVG treats the transparent keyword ...
Read more >Color Reference - React Native
Components in React Native are styled using JavaScript. Color properties usually match how CSS works on the web. General guides on the color...
Read more >Functions of React Native Color with Examples - eduCBA
The styling of React Native Components is done using JavaScript. ... In the example below, we have colored the background through backgroundColor: “cyan” ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mdalpozzo I could get it to work by calling the prop both in the config and the component
fill
instead ofcolor
. Can you try if that fixes it for you too?thanks! thats the trick