UNPKG

react-native-sortables

Version:

Powerful Sortable Components for Flexible Content Reordering in React Native

35 lines (32 loc) 981 B
"use strict"; import { useCallback, useEffect } from 'react'; import { clearAnimatedTimeout, setAnimatedTimeout } from '../utils/animatedTimeout'; import useMutableValue from './useMutableValue'; export default function useAnimatedDebounce() { const updateTimeoutId = useMutableValue(-1); useEffect(() => { return () => { clearAnimatedTimeout(updateTimeoutId.value); }; }, [updateTimeoutId]); const cancel = useCallback(() => { 'worklet'; clearAnimatedTimeout(updateTimeoutId.value); updateTimeoutId.value = -1; }, [updateTimeoutId]); const schedule = useCallback((callback, timeout) => { 'worklet'; if (updateTimeoutId.value !== -1) { clearAnimatedTimeout(updateTimeoutId.value); } updateTimeoutId.value = setAnimatedTimeout(() => { callback(); updateTimeoutId.value = -1; }, timeout); }, [updateTimeoutId]); return { cancel, schedule }; } //# sourceMappingURL=useAnimatedDebounce.js.map