| import { useEffect } from 'react';
|
| import {
|
| useSharedValue,
|
| withDelay,
|
| withSpring,
|
| withTiming,
|
| runOnJS,
|
| } from 'react-native-reanimated';
|
|
|
| interface AnimationSequenceConfig {
|
| scoreDuration?: number;
|
| confettiDelay?: number;
|
| rankDelay?: number;
|
| comboDelay?: number;
|
| }
|
|
|
| export const useAnimationSequence = (
|
| {
|
| scoreDuration = 2500,
|
| confettiDelay = 0,
|
| rankDelay = 200,
|
| comboDelay = 600,
|
| }: AnimationSequenceConfig = {},
|
| onConfettiTrigger?: () => void
|
| ) => {
|
|
|
| const scoreProgress = useSharedValue(0);
|
|
|
| const rankRevealProgress = useSharedValue(0);
|
|
|
| const comboScale = useSharedValue(0);
|
|
|
| useEffect(() => {
|
|
|
| scoreProgress.value = withTiming(1, { duration: scoreDuration }, (finished) => {
|
| 'worklet';
|
| if (finished && onConfettiTrigger) {
|
| runOnJS(onConfettiTrigger)();
|
| }
|
| });
|
|
|
|
|
| rankRevealProgress.value = withDelay(
|
| scoreDuration + rankDelay,
|
| withTiming(1, { duration: 600 })
|
| );
|
|
|
|
|
| comboScale.value = withDelay(
|
| scoreDuration + rankDelay + comboDelay,
|
| withSpring(1, { damping: 10, stiffness: 80 })
|
| );
|
| }, []);
|
|
|
| return {
|
| scoreProgress,
|
| rankRevealProgress,
|
| comboScale,
|
| };
|
| };
|
|
|