I want to make an animation to rotate 90 deg up or down if an icon from the div it's pressed.It should rotate down if show is false, and viceversa.This is my code:
const [show, setShow] = useState(false)const spinValue = new Animated.Value(0)const spin = spinValue.interpolate({inputRange: [0, 1],outputRange: ["0deg", `${!show ? "-" : ""}90deg`],})const handleIcon = async () => { setShow(!show) Animated.timing(spinValue, { toValue: 1, duration: 300, easing: Easing.linear, useNativeDriver: true,}).start()
}
<Animated.View style={{ transform: [{ rotate: spin }] }}><AntIcon name="left" size={22} onPress={handleIcon} /></Animated.View>
It works only for first time if I remove setShow(!show) from the handleIcon function.Do someone know what I did wrong? It is my first animation in react native.Thank you!