import React, { useRef, useState } from 'react' import Lottie from 'lottie-react-native'; import { TouchableOpacity, Easing, ViewStyle, Animated } from 'react-native'; import IconAntDesign from 'react-native-vector-icons/AntDesign' import { useTheme } from 'styled-components'; interface Props { initialValue: number, onClick: any, disableAnimation?: boolean toValue: number, style?: ViewStyle, duration?: number, type: 'favorite', // animation types isActive: boolean, animationType?: ((value: number) => number); useNativeDriver?: boolean, iconProps?: { color?: string, size?: number, style?: ViewStyle } } export const LottieAnimation = (props: Props) => { const { initialValue, onClick, disableAnimation, toValue, style, duration, type, isActive, useNativeDriver, animationType, iconProps } = props const theme = useTheme() const animationProgress = useRef(new Animated.Value(initialValue)) const favRef = useRef(null) const [isHide, setIsHide] = useState(true) const favoriteArray = ['heart', 'hearto'] const icon = type === 'favorite' ? favoriteArray : [] const animationGif = type === 'favorite' ? theme.images?.general?.heart : '' const onPressLottie = () => { if (!disableAnimation) { if (type === 'favorite') { favRef.current?.play() } else { setIsHide(false) Animated.timing(animationProgress.current, { toValue, duration: duration || 5000, easing: animationType || Easing.linear, useNativeDriver: useNativeDriver ?? true }).start(); hideLottie() } } onClick() } const hideLottie = () => { setTimeout(() => setIsHide(true), 4500) } return ( {type === 'favorite' ? ( // ) : ( <> {!isHide && } )} ) }