Skip to content

Instantly share code, notes, and snippets.

@flunder
Created September 4, 2023 09:30
Show Gist options
  • Save flunder/0b91b9c1aae2ed7294035b6871a5b1c4 to your computer and use it in GitHub Desktop.
Save flunder/0b91b9c1aae2ed7294035b6871a5b1c4 to your computer and use it in GitHub Desktop.
import React, { useRef, useEffect } from 'react';
import { Animated, Easing } from 'react-native';
import { useIsMounted } from '@t/utils/hooks/useIsMounted';
export const useEyesAnimation = () => {
const offsetX = useRef(new Animated.Value(0)).current;
const isMounted = useIsMounted();
useEffect(() => {
animate();
}, []);
const animate = () => {
offsetX.setValue(0);
Animated.sequence([
Animated.timing(offsetX, {
easing: Easing.inOut(Easing.quad),
duration: 2000,
toValue: -5,
useNativeDriver: true,
}),
Animated.timing(offsetX, {
easing: Easing.inOut(Easing.quad),
duration: 2000,
toValue: 0,
useNativeDriver: true,
}),
]).start(() => {
if (isMounted()) animate();
});
};
return { eyesOffsetX: offsetX };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment