import React, { useEffect } from "react"; import { TouchableOpacity, TouchableOpacityProps, View } from "react-native"; import { Text } from "@/components/common/Text"; import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, } from "react-native-reanimated"; import { Colors } from "@/constants/Colors"; interface NextEpisodeCountDownButtonProps extends TouchableOpacityProps { onFinish?: () => void; onPress?: () => void; show: boolean; } const NextEpisodeCountDownButton: React.FC = ({ onFinish, onPress, show, ...props }) => { const progress = useSharedValue(0); useEffect(() => { if (show) { progress.value = 0; progress.value = withTiming( 1, { duration: 10000, // 10 seconds easing: Easing.linear, }, (finished) => { if (finished && onFinish) { console.log("finish"); runOnJS(onFinish)(); } } ); } }, [show, onFinish]); const animatedStyle = useAnimatedStyle(() => { return { position: "absolute", left: 0, top: 0, bottom: 0, width: `${progress.value * 100}%`, backgroundColor: Colors.primary, }; }); const handlePress = () => { if (onPress) { onPress(); } }; if (!show) { return null; } return ( Next Episode ); }; export default NextEpisodeCountDownButton;