mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 12:33:26 +00:00
25 lines
777 B
TypeScript
25 lines
777 B
TypeScript
import { useCallback, useState } from "react";
|
|
import { useSharedValue } from "react-native-reanimated";
|
|
|
|
import { useDebounce } from "../useDebounce";
|
|
|
|
export const useVolume = () => {
|
|
const [showVolumeOverlay, setShowVolumeOverlay] = useState(false);
|
|
const debouncedShowVolumeOverlay = useDebounce(showVolumeOverlay, 20);
|
|
const volume = useSharedValue(1);
|
|
const debouncedVolume = useDebounce(volume.value, 20);
|
|
|
|
const handleVolumeChange = useCallback((newValue: number) => {
|
|
volume.value = newValue;
|
|
setShowVolumeOverlay(true);
|
|
}, []);
|
|
|
|
return {
|
|
showVolumeOverlay: debouncedShowVolumeOverlay,
|
|
currentVolume: volume,
|
|
debouncedVolume: `${Math.round(debouncedVolume * 100)}%`,
|
|
setShowVolumeOverlay,
|
|
handleVolumeChange,
|
|
} as const;
|
|
};
|