react-native-ruler-view
Version:
⚡ Lightning-fast and customizable Ruler Picker component for React Native
29 lines (27 loc) • 1.05 kB
JavaScript
;
// export const calculateCurrentValue = (
// scrollPosition: number,
// stepWidth: number,
// gapBetweenItems: number,
// min: number,
// max: number,
// step: number,
// fractionDigits: number
// ) => {
// const index = Math.round(scrollPosition / (stepWidth + gapBetweenItems));
// return Math.min(Math.max(index * step + min, min), max).toFixed(
// fractionDigits
// );
// };
export const calculateCurrentValue = (offset, stepWidth, gapBetweenSteps, min, max, step, fractionDigits) => {
const totalStepWidth = stepWidth + gapBetweenSteps;
const currentStep = Math.round(offset / totalStepWidth);
const value = min + currentStep * step;
const clampedValue = Math.min(Math.max(value, min), max);
return clampedValue.toFixed(fractionDigits);
};
export const getInitialOffset = (initialValue, min, step, stepWidth, gapBetweenSteps) => {
const initialIndex = Math.floor((initialValue - min) / step);
return initialIndex * (stepWidth + gapBetweenSteps);
};
//# sourceMappingURL=calculations.js.map