UNPKG

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

Version:
30 lines (29 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useKeyboardAvoidingSnapPoints = useKeyboardAvoidingSnapPoints; var _reactNativeReanimated = require("react-native-reanimated"); var _context = require("../context"); var _utils = require("../utils"); /** * Performs some adjustments to a normalized array of snap-points to account for the keyboard. * * TODO: right now, we just expand proportionally with the keyboard. However, it would be nice * to offer a wider selection strategies such as expanding to largest snap-point etc. */ function useKeyboardAvoidingSnapPoints(normalizedSnapPointsSharedValue) { const keyboardHeightSharedValue = (0, _context.useKeyboardHeightSharedValue)(); const { wrapperHeightSharedValue } = (0, _context.useBottomSheetToolboxInternalContext)(); return (0, _reactNativeReanimated.useDerivedValue)(() => { const wrapperHeight = wrapperHeightSharedValue.get(); const normalizedSnapPoints = normalizedSnapPointsSharedValue.get(); if (normalizedSnapPoints === null || wrapperHeight === null) return null; const keyboardAdjustedSnapPoints = normalizedSnapPoints.map(sp => sp === _utils.CLOSED_SNAP_POINT ? sp : sp + keyboardHeightSharedValue.get()); const wrapperClamped = keyboardAdjustedSnapPoints.map(sp => Math.min(sp, wrapperHeight)); return wrapperClamped; }, [keyboardHeightSharedValue, normalizedSnapPointsSharedValue, wrapperHeightSharedValue]); } //# sourceMappingURL=use-keyboard-avoiding-snap-points.js.map