react-native-ruler-view
Version:
⚡ Lightning-fast and customizable Ruler Picker component for React Native
35 lines (33 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getInitialOffset = exports.calculateCurrentValue = void 0;
// 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
// );
// };
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);
};
exports.calculateCurrentValue = calculateCurrentValue;
const getInitialOffset = (initialValue, min, step, stepWidth, gapBetweenSteps) => {
const initialIndex = Math.floor((initialValue - min) / step);
return initialIndex * (stepWidth + gapBetweenSteps);
};
exports.getInitialOffset = getInitialOffset;
//# sourceMappingURL=calculations.js.map