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.

SvgUri with Color

See original GitHub issue

How to set the color of svg loaded from url?

<SvgUri width="80%" height="80%" uri="https://unpkg.com/ionicons@5.0.0/dist/svg/person-outline.svg" color="red" fill="red" />

the snippet is not changing color.

Thank you.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

9reactions
midorimicicommented, Jun 17, 2021

Using SvgXml works for me too! To change SvgUri to SvgXml, I simply used fetch like this. I give a closed tag to the useState, that otherwise Unexpected end of input error occurs.

const [imgXml, setImgXml] = useState('<svg></svg>');

useEffect(() => {
  getImgXml();
}, []);

const getImgXml = async () => {
  const url = await getURL();
  const xml = await (await fetch(url)).text();
  setImgXml(xml);
};

<SvgXml
  xml={imgXml
    .replace(/fill="#[0-9a-f]{6}"/g, `fill="${props.fill}"`)
    .replace(/stroke="#[0-9a-f]{6}"/g, `stroke="${props.stroke}"`)}
  width={pieceSize}
  height={pieceSize}
/>
1reaction
bisk8scommented, Jul 2, 2020

I’ve used this workaround for my icons:

<SvgXml width={45} height={45} xml={xml.replace(/black/g, 'red')} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

SvgUri with Color · Issue #1317 - GitHub
I understood that 'color' and 'fill' props intended to override all 'fill' and 'color' attributes on file. That would be great to have...
Read more >
How to change color of SVG on react native? - Stack Overflow
Ok so it seems that the eva-icons are not fully supported by SvgUri. This is caused by a different svg/xml structure, so I...
Read more >
How to display SVG files and change colors dynamically in ...
Changing colors dynamically1 (for single color). Just change the fill part of the SVG file to "currentColor" (the same way you change the...
Read more >
Developers - SvgUri with Color - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
How to use SVG with Dynamic colors in React Native - Medium
How to use SVG with Dynamic colors in React Native. Dynamically Change SVG fill color. What is SVG? Scalable Vector ...
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