UNPKG

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

Version:
27 lines (25 loc) 1.4 kB
"use strict"; import { useDerivedValue } from "react-native-reanimated"; import { useBottomSheetToolboxInternalContext, useKeyboardHeightSharedValue } from "../context"; import { CLOSED_SNAP_POINT } from "../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. */ export function useKeyboardAvoidingSnapPoints(normalizedSnapPointsSharedValue) { const keyboardHeightSharedValue = useKeyboardHeightSharedValue(); const { wrapperHeightSharedValue } = useBottomSheetToolboxInternalContext(); return useDerivedValue(() => { const wrapperHeight = wrapperHeightSharedValue.get(); const normalizedSnapPoints = normalizedSnapPointsSharedValue.get(); if (normalizedSnapPoints === null || wrapperHeight === null) return null; const keyboardAdjustedSnapPoints = normalizedSnapPoints.map(sp => sp === 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