简体   繁体   中英

How to spin an image infinitely in React Native

I'm trying to spin an image infinitely, a rotating disk. I checked using animated or the react-native-animatable . They've got duration and timing, how do I rotate without putting a time or angle of spin to it.

  const handleAnimation = () => {
      Animated.timing(rotateAnimation, {
          toValue: 1,
          duration: 72000,
          useNativeDriver: false,
      }).start(() => {
          rotateAnimation.setValue(0);
      });
  }; 
    <TouchableOpacity onPress={async () => handleAnimation()}>
                <Animated.Image
                    style={{
                        width: 300,
                        height: 300,
                        transform: [{ rotate: interpolateRotating }]
                    }}
                    source={abcd} >
                </Animated.Image>
            </TouchableOpacity>

Try adding the Animated.timing in a Animated.loop

Animated.loop(
    Animated.timing(rotateAnimation, {
         toValue: 1,
         duration: 72000,
         useNativeDriver: false,
     })
).start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM