Head-shake — subtle head shake.
Implementation:
1import { Animated } from "react-native";23function HeadShakeView({ children }) {4 const shakeAnim = useRef(new Animated.Value(0)).current;56 useEffect(() => {7 Animated.sequence([8 Animated.timing(shakeAnim, {9 toValue: 0.06,10 duration: 60,11 useNativeDriver: true,12 }),13 Animated.timing(shakeAnim, {14 toValue: -0.06,15 duration: 60,16 useNativeDriver: true,17 }),18 Animated.timing(shakeAnim, {19 toValue: 0.04,20 duration: 60,21 useNativeDriver: true,22 }),23 Animated.timing(shakeAnim, {24 toValue: -0.04,25 duration: 60,26 useNativeDriver: true,27 }),28 Animated.timing(shakeAnim, {29 toValue: 0,30 duration: 60,31 useNativeDriver: true,32 }),33 ]).start();34 }, []);3536 return (37 <Animated.View style={{ transform: [{ rotate: shakeAnim.interpolate({38 inputRange: [-0.06, 0, 0.06],39 outputRange: ["-2deg", "0deg", "2deg"],40 }) }] }}>41 {children}42 </Animated.View>43 );44}