-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The fill
and stroke
props aren't animated
#2561
Comments
Hey @grevtsovna, const AnimatedSvg = Animated.createAnimatedComponent(Svg);
const AnimatedG = Animated.createAnimatedComponent(G);
function Example() {
const sv = useSharedValue(0);
const runAnimation = () => { sv.value = withTiming(sv.value ? 0 : 1) };
const animatedSvgProps = useAnimatedProps(() => {
return {
width: interpolate(sv.value, [0, 1], [50, 100], Extrapolation.CLAMP),
height: interpolate(sv.value, [0, 1], [50, 100], Extrapolation.CLAMP),
};
});
const animatedGProps = useAnimatedProps(() => {
return {
color: interpolateColor(sv.value, [0, 1], ['blue', 'violet']),
fill: interpolateColor(
sv.value,
[0, 1],
['rgb(255,0,0)', 'rgb(0,255,0)'],
),
stroke: interpolateColor(
sv.value,
[0, 1],
['rgb(0,0,255)', 'rgb(255,0,0)'],
),
};
});
return (
<>
<AnimatedSvg viewBox="-16 -16 544 544" animatedProps={animatedSvgProps}>
<AnimatedG animatedProps={animatedGProps}>
<Path
d="M318.37,85.45L422.53,190.11,158.89,455,54.79,350.38ZM501.56,60.2L455.11,13.53a45.93,45.93,0,0,0-65.11,0L345.51,58.24,449.66,162.9l51.9-52.15A35.8,35.8,0,0,0,501.56,60.2ZM0.29,497.49a11.88,11.88,0,0,0,14.34,14.17l116.06-28.28L26.59,378.72Z"
strokeWidth="32"
/>
<Path d="M0,0L512,512" stroke="currentColor" strokeWidth="32" />
<Path d="M512,0L0,512" stroke="currentColor" strokeWidth="32" />
</AnimatedG>
</AnimatedSvg>
<Button title="Run Animation" onPress={runAnimation} />
</>
);
} |
Hi @jakex7, However, I should mention that it might not be easy to apply in some cases. For example, initially, I faced the issue when I was trying to animate an icon from |
Description
I've encountered some problems with animating SVG. It looks like there's a problem when I try animating
stroke
andfill
props. Animations work fine with other props aswidth
,height
andcolor
.I've also tried to animate this either with or without adapter (
createAnimatedPropAdapter
). The result is the same.Here's a Snack without adapter - https://snack.expo.dev/v5hIak6G8R1Sc6d4PvZXZ
Versions of react-native-reanimated I've tried - 3.15.5 and 3.16.1
Steps to reproduce
SharedValue
SharedValue
from 0 to 1 and vice versastroke
andfill
, usinguseAnimatedProps
and apply them to a SVG element.Snack or a link to a repository
https://snack.expo.dev/9B8O7pBATpv9u7YumqCSA?platform=android
SVG version
15.8.0
React Native version
0.74.5
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Paper (Old Architecture)
Build type
Debug app & dev bundle
Device
iOS simulator
Device model
No response
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: