mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:53:25 +00:00
volume cleanup
This commit is contained in:
24
apps/expo/src/hooks/player/useVolume.ts
Normal file
24
apps/expo/src/hooks/player/useVolume.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
};
|
Reference in New Issue
Block a user