I have a Pressable component and inside it I have an icon. I want to press it and rotate it 180 degrees. But the animation only works once. When I click again nothing happens.
const animation = useSharedValue(0);
const rotation = useDerivedValue(() => {
return interpolate(animation.value, [0, 180], [0, 65]);
});
const animationStyle = useAnimatedStyle(() => {
return {
transform: [
{
rotate: rotation.value + "deg",
},
],
};
});
const startAnimation = () => {
setShowDetail(!showDetail);
animation.value = withTiming(500, {
duration: 300,
});
};
In the component
<Animated.View style={[animationStyle]}>
<Icons/>
</Animated.View>