mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
42 lines
1020 B
TypeScript
42 lines
1020 B
TypeScript
import { useCallback, useEffect, useRef, useState } from "react";
|
|
import {
|
|
runOnJS,
|
|
useAnimatedReaction,
|
|
useSharedValue,
|
|
} from "react-native-reanimated";
|
|
|
|
export const useControlsVisibility = (timeout: number = 3000) => {
|
|
const opacity = useSharedValue(1);
|
|
|
|
const hideControlsTimerRef = useRef<ReturnType<typeof setTimeout> | null>(
|
|
null
|
|
);
|
|
|
|
const showControls = useCallback(() => {
|
|
opacity.value = 1;
|
|
if (hideControlsTimerRef.current) {
|
|
clearTimeout(hideControlsTimerRef.current);
|
|
}
|
|
hideControlsTimerRef.current = setTimeout(() => {
|
|
opacity.value = 0;
|
|
}, timeout);
|
|
}, [timeout]);
|
|
|
|
const hideControls = useCallback(() => {
|
|
opacity.value = 0;
|
|
if (hideControlsTimerRef.current) {
|
|
clearTimeout(hideControlsTimerRef.current);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
if (hideControlsTimerRef.current) {
|
|
clearTimeout(hideControlsTimerRef.current);
|
|
}
|
|
};
|
|
}, []);
|
|
|
|
return { opacity, showControls, hideControls };
|
|
};
|