Skip to content

Commit 20ec0d3

Browse files
committed
fix: resolve TDZ error by moving function definitions before useEffect
1 parent 1d91577 commit 20ec0d3

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

packages/shared-ui/src/screens/PlayerScreen.tsx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ export default function PlayerScreen() {
3030
const currentTimeRef = useRef<number>(0);
3131
const durationRef = useRef<number>(0);
3232

33+
const showControls = useCallback(() => {
34+
setControlsVisible(true);
35+
36+
if (hideControlsTimeoutRef.current) {
37+
clearTimeout(hideControlsTimeoutRef.current);
38+
}
39+
hideControlsTimeoutRef.current = setTimeout(() => {
40+
setControlsVisible(false);
41+
}, 5000);
42+
}, []);
43+
44+
const seek = useCallback((time: number) => {
45+
if (time < 0) {
46+
time = 0;
47+
} else if (time > durationRef.current) {
48+
time = durationRef.current;
49+
}
50+
videoRef.current?.seek(time);
51+
currentTimeRef.current = time;
52+
setCurrentTime(time);
53+
showControls();
54+
}, [showControls]);
55+
56+
const togglePausePlay = useCallback(() => {
57+
setPaused((prev) => !prev);
58+
showControls();
59+
}, [showControls]);
60+
3361
useEffect(() => {
3462
if (SHOW_NATIVE_CONTROLS) return;
3563

@@ -61,34 +89,6 @@ export default function PlayerScreen() {
6189
};
6290
}, [seek, togglePausePlay, showControls, navigation]);
6391

64-
const showControls = useCallback(() => {
65-
setControlsVisible(true);
66-
67-
if (hideControlsTimeoutRef.current) {
68-
clearTimeout(hideControlsTimeoutRef.current);
69-
}
70-
hideControlsTimeoutRef.current = setTimeout(() => {
71-
setControlsVisible(false);
72-
}, 5000);
73-
}, []);
74-
75-
const seek = useCallback((time: number) => {
76-
if (time < 0) {
77-
time = 0;
78-
} else if (time > durationRef.current) {
79-
time = durationRef.current;
80-
}
81-
videoRef.current?.seek(time);
82-
currentTimeRef.current = time;
83-
setCurrentTime(time);
84-
showControls();
85-
}, [showControls]);
86-
87-
const togglePausePlay = useCallback(() => {
88-
setPaused((prev) => !prev);
89-
showControls();
90-
}, [showControls]);
91-
9292
// Show controls when video starts
9393
useEffect(() => {
9494
if (durationRef.current && !SHOW_NATIVE_CONTROLS) {

0 commit comments

Comments
 (0)