Created
September 4, 2023 09:30
-
-
Save lrsbt/0b91b9c1aae2ed7294035b6871a5b1c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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