@attio/react-native-bottom-sheet-toolbox
Version:
17 lines (15 loc) • 544 B
JavaScript
;
/**
* Snap the given value to the closest point, taking into account the velocity.
*/
export function snapPoint(value, velocity, points, projectionScale = 0.2) {
"worklet";
if (points.length === 0) {
throw new Error("Must provide at least one snap-point.");
}
const projectedPoint = value + velocity * projectionScale;
const deltas = points.map(p => Math.abs(projectedPoint - p));
const minDelta = Math.min(...deltas);
return points[deltas.indexOf(minDelta)] ?? null;
}
//# sourceMappingURL=snap-point.js.map