UNPKG

react-native-sticky-range-slider

Version:

[React Native | TypeScript] A pure TypeScript component offering a customizable range slider optimized for performance. It supports dragging functionalities for selecting a range of values, with values that smoothly follow the thumb. This component is ful

32 lines (31 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isLowCloser = exports.getValueForPosition = exports.clamp = void 0; const isLowCloser = (downX, lowPosition, highPosition) => { if (lowPosition === highPosition) { return downX < lowPosition; } const distanceFromLow = Math.abs(downX - lowPosition); const distanceFromHigh = Math.abs(downX - highPosition); return distanceFromLow < distanceFromHigh; }; exports.isLowCloser = isLowCloser; const clamp = (value, min, max) => { return Math.min(Math.max(value, min), max); }; exports.clamp = clamp; const getValueForPosition = (positionInView, containerWidth, thumbWidth, min, max, step) => { const availableSpace = containerWidth - thumbWidth; const relStepUnit = step / (max - min); let relPosition = (positionInView - thumbWidth / 2) / availableSpace; const relOffset = relPosition % relStepUnit; relPosition -= relOffset; if (relOffset / relStepUnit >= 0.5) { relPosition += relStepUnit; } return clamp(min + Math.round(relPosition / relStepUnit) * step, min, max); }; exports.getValueForPosition = getValueForPosition; //# sourceMappingURL=helpers.js.map