UNPKG

@attio/react-native-bottom-sheet-toolbox

Version:
36 lines (33 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useNormalizedSnapPoints = useNormalizedSnapPoints; var _reactNativeReanimated = require("react-native-reanimated"); var _context = require("../context"); var _utils = require("../utils"); /** * Normalizes an array of SnapPoints to a SharedValue array of positions represented as numbers. */ function useNormalizedSnapPoints(snapPoints) { const { childrenHeightSharedValue, wrapperHeightSharedValue, footerHeightSharedValue } = (0, _context.useBottomSheetToolboxInternalContext)(); return (0, _reactNativeReanimated.useDerivedValue)(() => { const unsorted = snapPoints.map(sp => (0, _utils.normalizeSheetPosition)({ sheetPosition: sp, childrenHeightSharedValue, wrapperHeightSharedValue, footerHeightSharedValue })); const isPrepared = unsorted.every(snapPoint => snapPoint !== null); if (!isPrepared) return null; const prepared = unsorted; prepared.sort((a, b) => a - b); // TODO: these should probably be clamped to the sheets bounds. return prepared; }, [childrenHeightSharedValue, wrapperHeightSharedValue, footerHeightSharedValue, snapPoints]); } //# sourceMappingURL=use-normalized-snap-points.js.map