Skip to content

Commit 440a888

Browse files
committed
Refactor AnimationControl and CurrentTrackManager for improved animation handling and timing
- Updated AnimationControl to utilize refs for managing animation triggers, ensuring animations are executed only once per cycle. - Adjusted animation timing in CurrentTrackManager, increasing the total animation duration for smoother transitions.
1 parent 48104c6 commit 440a888

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/components/OBS_Components/SoundRequest/CurrentTrack/AnimationControl.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Variant,
66
Variants,
77
} from "framer-motion";
8-
import { useCallback, useEffect, useState } from "react";
8+
import { useEffect, useRef, useState } from "react";
99

1010
import styles from "./CurrentTrack.module.scss";
1111

@@ -33,18 +33,21 @@ export default function AnimationControl({
3333
const [animationStage, setAnimationStage] = useState<AnimationStage>("idle");
3434
const [nowPlayingCount, setNowPlayingCount] = useState(0);
3535

36-
const startAnimation = useCallback(() => {
37-
if (!AnimationStart || animationStage !== "idle") return;
38-
39-
setAnimationStage("compressIn");
40-
setNowPlayingCount(0);
41-
}, [AnimationStart, animationStage]);
42-
36+
// Запускаем анимацию ровно один раз на цикл AnimationStart=true
37+
const hasTriggeredRef = useRef(false);
38+
const hasSwappedRef = useRef(false);
4339
useEffect(() => {
44-
if (AnimationStart) {
45-
startAnimation();
40+
if (AnimationStart && !hasTriggeredRef.current) {
41+
hasTriggeredRef.current = true;
42+
setAnimationStage("compressIn");
43+
setNowPlayingCount(0);
44+
hasSwappedRef.current = false;
4645
}
47-
}, [AnimationStart, startAnimation]);
46+
if (!AnimationStart) {
47+
hasTriggeredRef.current = false;
48+
hasSwappedRef.current = false;
49+
}
50+
}, [AnimationStart]);
4851

4952
const handleAnimationComplete = (stage: AnimationStage) => {
5053
switch (stage) {
@@ -59,7 +62,10 @@ export default function AnimationControl({
5962
break;
6063
case "compressInFinal":
6164
setAnimationStage("compressOutFinal");
62-
swapTrack();
65+
if (!hasSwappedRef.current) {
66+
hasSwappedRef.current = true;
67+
swapTrack();
68+
}
6369
break;
6470
case "compressOutFinal":
6571
setAnimationStage("showChildren");

src/components/OBS_Components/SoundRequest/CurrentTrack/CurrentTrackManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function CurrentTrackManager() {
109109
);
110110

111111
// Общая длительность ступенчатой анимации (сжатие/разжатие → NOW PLAYING → сжатие/разжатие → показ контента)
112-
const ANIMATION_TOTAL_MS = 6200;
112+
const ANIMATION_TOTAL_MS = 8000;
113113

114114
// Таймер завершения анимации
115115
const animationTimer = useRef<number | null>(null);

0 commit comments

Comments
 (0)