UNPKG

react-native-sortables

Version:

Powerful Sortable Components for Flexible Content Reordering in React Native

43 lines (38 loc) 1.03 kB
"use strict"; import { makeMutable } from 'react-native-reanimated'; const PENDING_TIMEOUTS = makeMutable({}); const TIMEOUT_ID = makeMutable(0); function removeFromPendingTimeouts(id) { 'worklet'; PENDING_TIMEOUTS.modify(pendingTimeouts => { 'worklet'; delete pendingTimeouts[id]; return pendingTimeouts; }); } export function setAnimatedTimeout(callback, delay = 0) { 'worklet'; let startTimestamp; const currentId = TIMEOUT_ID.value; PENDING_TIMEOUTS.value[currentId] = true; TIMEOUT_ID.value += 1; const step = newTimestamp => { if (!PENDING_TIMEOUTS.value[currentId]) { return; } startTimestamp ??= newTimestamp; if (newTimestamp > startTimestamp + delay) { removeFromPendingTimeouts(currentId); callback(); return; } requestAnimationFrame(step); }; requestAnimationFrame(step); return currentId; } export function clearAnimatedTimeout(handle) { 'worklet'; removeFromPendingTimeouts(handle); } //# sourceMappingURL=animatedTimeout.js.map