mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
Some checks failed
🤖 Android APK Build / 🏗️ Build Android APK (push) Has been cancelled
🤖 iOS IPA Build / 🏗️ Build iOS IPA (push) Has been cancelled
🔒 Lockfile Consistency Check / 🔍 Check bun.lock and package.json consistency (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (javascript-typescript) (push) Has been cancelled
🏷️🔀Merge Conflict Labeler / 🏷️ Labeling Merge Conflicts (push) Has been cancelled
🕒 Handle Stale Issues / 🗑️ Cleanup Stale Issues (push) Has been cancelled
38 lines
966 B
TypeScript
38 lines
966 B
TypeScript
import { useCallback, useEffect, useRef } from "react";
|
|
import { useSharedValue } from "react-native-reanimated";
|
|
|
|
export const useControlsVisibility = (timeout = 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 };
|
|
};
|