File size: 1,462 Bytes
0bedb61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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

) => {
  // 0 to 1 for score
  const scoreProgress = useSharedValue(0);
  // 0 to 1 for rank reveal
  const rankRevealProgress = useSharedValue(0);
  // 0 to 1 for combo badge
  const comboScale = useSharedValue(0);
  
  useEffect(() => {
    // 1. Start score counter
    scoreProgress.value = withTiming(1, { duration: scoreDuration }, (finished) => {
      'worklet';
      if (finished && onConfettiTrigger) {
        runOnJS(onConfettiTrigger)();
      }
    });

    // 2. Rank Reveal (after score + rankDelay)
    rankRevealProgress.value = withDelay(
      scoreDuration + rankDelay,
      withTiming(1, { duration: 600 })
    );

    // 3. Combo Badge (after rank + comboDelay)
    comboScale.value = withDelay(
      scoreDuration + rankDelay + comboDelay,
      withSpring(1, { damping: 10, stiffness: 80 })
    );
  }, []);

  return {
    scoreProgress,
    rankRevealProgress,
    comboScale,
  };
};