Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change color icon using Lottie Animation #84

Open
rafael-fecha opened this issue Mar 9, 2023 · 4 comments
Open

How to change color icon using Lottie Animation #84

rafael-fecha opened this issue Mar 9, 2023 · 4 comments

Comments

@rafael-fecha
Copy link

The same as other lottie packages like lottie react native supports colorFilters:

colorFilters={[
                    {
                        keypath: 'somekeypath',
                        color: 'someColor
                    },

I would like to know if it is possible to achieve color icon changing in this package.

Thanks !

@rafael-fecha
Copy link
Author

@Gamote no updates here ?

@jonscottclark
Copy link

@rafael-fecha We send the Lottie container to styled-components, and set color of the child svg:

const StyledLottie = styled(Lottie)`
  svg,
  svg path {
    fill: currentColor; // we use `currentColor` to inherit from parent
    stroke: currentColor; // (or whatever colour value you want)
  }
`;
const LoadingAnimation = () => {
  return (
    <StyledLottie
      loop
      autoplay
      animationData={animationData}
    />
  );
};

Hope that helps.

@dentemm
Copy link

dentemm commented Mar 19, 2024

@jonscottclark that works, thanks! Can you also explain what the syntax would look like to change the color for a single path by name?

@dentemm
Copy link

dentemm commented Mar 19, 2024

@jonscottclark that works, thanks! Can you also explain what the syntax would look like to change the color for a single path by name?

After digging into the developer console I found a solution:

export const StyledLottie = styled(Lottie)`
  svg path[fill="rgb(205,160,111)"] { // or whatever color you have
    fill: hotpink;
  }
`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants