@attio/react-native-bottom-sheet-toolbox
Version:
38 lines (35 loc) • 1.58 kB
JavaScript
;
import { CONTENT_HEIGHT_SNAP_POINT, CONTENT_HEIGHT_WITH_OVERLAY_FOOTER_SNAP_POINT } from "../utils/constants";
import { getPercentageValue } from "../utils/get-percentage-value";
export function getSheetPositionValue(value) {
"worklet";
return value !== null && typeof value === "object" && "value" in value ? value.get() : value;
}
export function normalizeSheetPosition({
sheetPosition,
childrenHeightSharedValue,
wrapperHeightSharedValue,
footerHeightSharedValue
}) {
"worklet";
const sheetPositionValue = getSheetPositionValue(sheetPosition);
if (sheetPositionValue === CONTENT_HEIGHT_SNAP_POINT) {
return childrenHeightSharedValue.get();
} else if (sheetPositionValue === CONTENT_HEIGHT_WITH_OVERLAY_FOOTER_SNAP_POINT) {
const childrenHeight = childrenHeightSharedValue.get();
const footerHeight = footerHeightSharedValue.get();
return childrenHeight === null || footerHeight === null ? null : childrenHeight + footerHeight;
} else if (typeof sheetPositionValue === "number") {
return sheetPositionValue;
} else if (typeof sheetPositionValue === "string" && sheetPositionValue.endsWith("%")) {
const pv = getPercentageValue(sheetPositionValue);
if (pv !== null) {
const wrapperHeight = wrapperHeightSharedValue.get();
return wrapperHeight === null ? null : pv * wrapperHeight;
}
} else if (sheetPositionValue === null) {
return null;
}
throw new Error(`Malformed SheetPosition in bottom-sheet: ${JSON.stringify(sheetPosition)}.`);
}
//# sourceMappingURL=normalize-sheet-position.js.map