UNPKG

react-native-screen-transitions

Version:
51 lines (47 loc) 1.53 kB
"use strict"; import { animate } from "../animation/animate"; import { velocity } from "./velocity"; export const resetGestureValues = ({ spec, gestures, shouldDismiss, event, dimensions }) => { "worklet"; const vxNorm = velocity.normalize(event.velocityX, dimensions.width); const vyNorm = velocity.normalize(event.velocityY, dimensions.height); // Ensure spring starts moving toward zero using normalized gesture values for direction. const nx = gestures.normalizedX.value || event.translationX / Math.max(1, dimensions.width); const ny = gestures.normalizedY.value || event.translationY / Math.max(1, dimensions.height); const vxTowardZero = velocity.calculateRestoreVelocity(nx, vxNorm); const vyTowardZero = velocity.calculateRestoreVelocity(ny, vyNorm); let remainingAnimations = 4; const onFinish = finished => { "worklet"; if (!finished) return; remainingAnimations -= 1; if (remainingAnimations === 0) { gestures.direction.value = null; } }; gestures.x.value = animate(0, { ...spec, velocity: vxTowardZero }, onFinish); gestures.y.value = animate(0, { ...spec, velocity: vyTowardZero }, onFinish); gestures.normalizedX.value = animate(0, { ...spec, velocity: vxTowardZero }, onFinish); gestures.normalizedY.value = animate(0, { ...spec, velocity: vyTowardZero }, onFinish); gestures.isDragging.value = 0; gestures.isDismissing.value = Number(shouldDismiss); }; //# sourceMappingURL=reset-gesture-values.js.map