UNPKG

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

Version:
50 lines (49 loc) 1.92 kB
"use strict"; import { GestureDetector } from "react-native-gesture-handler"; import { useAnimatedRef, useAnimatedScrollHandler, useSharedValue } from "react-native-reanimated"; import { useBottomSheetScrollGesture } from "../hooks"; import { jsx as _jsx } from "react/jsx-runtime"; export function BottomSheetScrollGestureDetector({ children, ...rest }) { const gesture = useBottomSheetScrollGesture(rest); return /*#__PURE__*/_jsx(GestureDetector, { gesture: gesture, children: children }); } export function useBottomSheetScrollGestureDetectorConnector(scrollDefaults = {}) { const scrollRef = useAnimatedRef(); const scrollOffsetYSharedValue = useSharedValue(0); const scrollContentHeightSharedValue = useSharedValue(null); const scrollLayoutHeightSharedValue = useSharedValue(null); const scrollHandler = useAnimatedScrollHandler({ onScroll: (event, context) => { scrollDefaults.onScroll?.(event, context); scrollOffsetYSharedValue.set(event.contentOffset.y); scrollContentHeightSharedValue.set(event.contentSize.height); scrollLayoutHeightSharedValue.set(event.layoutMeasurement.height); }, onBeginDrag: (event, context) => { scrollDefaults.onBeginDrag?.(event, context); }, onEndDrag: (event, context) => { scrollDefaults.onEndDrag?.(event, context); }, onMomentumBegin: (event, context) => { scrollDefaults.onMomentumBegin?.(event, context); }, onMomentumEnd: (event, context) => { scrollDefaults.onMomentumEnd?.(event, context); } }, [scrollDefaults.onScroll, scrollDefaults.onBeginDrag, scrollDefaults.onEndDrag, scrollDefaults.onMomentumBegin, scrollDefaults.onMomentumEnd]); return { scrollRef, scrollHandler, scrollOffsetYSharedValue, scrollContentHeightSharedValue, scrollLayoutHeightSharedValue }; } //# sourceMappingURL=bottom-sheet-scroll-gesture-detector.js.map