Giter Club home page Giter Club logo

Comments (9)

kristerkari avatar kristerkari commented on May 27, 2024 3

@steobrien Nice! Would you have time to contribute a change to the README with instructions on how to do that?

from react-native-svg-transformer.

salaaar avatar salaaar commented on May 27, 2024

Same Issue!

from react-native-svg-transformer.

kristerkari avatar kristerkari commented on May 27, 2024

Thanks @cylim ! I know that this is a highly requested feature.

The reasons why there is no way to do change the colors dynamically yet, are:

  1. React Native's Metro packager/bundler does not seem to support any good way for the user to define a custom config to be passed to a library that is using a transformer (e.g. react-native-svg-transformer). I'm however considering doing the same thing that I did with the Sass transformer, which is to support a custom custom config in a less clean way: https://github.com/kristerkari/react-native-sass-transformer#sass-options
  2. The transformer is using SVGR, and I would not like to add any custom attributes/properties to this library on top of the ones that SVGR provides.

I am of course open for any ideas of how to support changing the fill color in a clean way and without adding hacks to this library. If you can think of some, let me know.

from react-native-svg-transformer.

steobrien avatar steobrien commented on May 27, 2024

From https://www.smooth-code.com/open-source/svgr/docs/options/#replace-attribute-value

You can specify dynamic property using curly braces: { '#000': "{props.color}" } or --replace-attr-values #000={props.color}. It is particularly useful with a custom template.

Could that work? Are dynamic properties supported here?

from react-native-svg-transformer.

steobrien avatar steobrien commented on May 27, 2024

^ seems to work for me!

from react-native-svg-transformer.

qwoodmansee avatar qwoodmansee commented on May 27, 2024

@steobrien I would also greatly appreciate a little writeup on how to do it. I can make the readme change if you just want to respond here

from react-native-svg-transformer.

cylim avatar cylim commented on May 27, 2024

Sorry for opening an issues and didn't check it, I had open a PR with the solution provided by @steobrien.

from react-native-svg-transformer.

steobrien avatar steobrien commented on May 27, 2024

Excuse the delay – thanks for taking care of this @cylim!

from react-native-svg-transformer.

roryabraham avatar roryabraham commented on May 27, 2024

For me, the solution provided by @steobrien worked for react-native-web (directly using the svgr webpack loader), but not for the native platforms, where react-native-svg-transformer is internally using svgr. Does anyone have this working on web, iOS, and Android?

from react-native-svg-transformer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.