question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing SVG fill color in JS Code -- need processColor() for IOS

See original GitHub issue

Followed 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
kristerkaricommented, Aug 9, 2019

@mdalpozzo I could get it to work by calling the prop both in the config and the component fill instead of color. Can you try if that fixes it for you too?

0reactions
mdalpozzocommented, Aug 16, 2019

thanks! thats the trick

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found