UNPKG

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

Version:
21 lines (20 loc) 1.01 kB
"use strict"; import { runOnJS, useAnimatedReaction } from "react-native-reanimated"; import { useBottomSheetToolboxInternalContext } from "../context"; export function useBottomSheetOnSnapDetection(onSnapChange) { const { isReadySharedValue, normalizedSnapPointsSharedValue, currentPositionSharedValue } = useBottomSheetToolboxInternalContext(); useAnimatedReaction(() => { const normalizedSnapPoints = normalizedSnapPointsSharedValue.get(); if (!isReadySharedValue.get() || normalizedSnapPoints === null) return null; const snapPointIndex = normalizedSnapPoints.indexOf(currentPositionSharedValue.get()); return snapPointIndex === -1 ? null : snapPointIndex; }, (currentSnapIndex, lastSnapIndex) => { if (currentSnapIndex === null) return; if (onSnapChange) runOnJS(onSnapChange)(currentSnapIndex, lastSnapIndex); }, [isReadySharedValue, normalizedSnapPointsSharedValue, currentPositionSharedValue]); } //# sourceMappingURL=use-bottom-sheet-on-snap-detection.js.map