Loading spinner — animated loading indicator.
Basic spinner:
1import { Animated, Easing } from "react-native";2import { useEffect, useRef } from "react";34function Spinner() {5 const spinAnim = useRef(new Animated.Value(0)).current;67 useEffect(() => {8 Animated.loop(9 Animated.timing(spinAnim, {10 toValue: 1,11 duration: 1000,12 easing: Easing.linear,13 useNativeDriver: true,14 })15 ).start();16 }, []);1718 const rotation = spinAnim.interpolate({19 inputRange: [0, 1],20 outputRange: ["0deg", "360deg"],21 });2223 return (24 <Animated.View25 style={{26 width: 50,27 height: 50,28 borderRadius: 25,29 borderWidth: 3,30 borderColor: "#ccc",31 borderTopColor: "#333",32 transform: [{ rotate: rotation }],33 }}34 />35 );36}
Pulse animation:
1const pulseAnim = useRef(new Animated.Value(1)).current;23Animated.loop(4 Animated.sequence([5 Animated.timing(pulseAnim, {6 toValue: 1.2,7 duration: 500,8 useNativeDriver: true,9 }),10 Animated.timing(pulseAnim, {11 toValue: 1,12 duration: 500,13 useNativeDriver: true,14 }),15 ])16).start();