Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

React Native: I want to make an animation for a View, it should rotate 90deg up or down(based on a boolean) when is pressed

$
0
0

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!


Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>