UNPKG

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

Version:
56 lines (55 loc) 2.35 kB
"use strict"; import * as React from "react"; import { useMergeRefs } from "react-merge-refs"; import { ScrollView } from "react-native"; import { BottomSheetScrollGestureDetector, useBottomSheetScrollGestureDetectorConnector } from "@attio/react-native-bottom-sheet-toolbox"; import { jsx as _jsx } from "react/jsx-runtime"; function makeFlashListScrollComponent(inverted) { return function FlashListScrollComponent({ onScroll, onLayout, onContentSizeChange, ref, ...p }) { const { scrollOffsetYSharedValue, scrollRef, scrollContentHeightSharedValue, scrollLayoutHeightSharedValue } = useBottomSheetScrollGestureDetectorConnector(); const innerOnScroll = React.useCallback(evt => { onScroll?.(evt); scrollOffsetYSharedValue.set(evt.nativeEvent.contentOffset.y); scrollLayoutHeightSharedValue.set(evt.nativeEvent.layoutMeasurement.height); scrollContentHeightSharedValue.set(evt.nativeEvent.contentSize.height); }, [onScroll, scrollOffsetYSharedValue, scrollLayoutHeightSharedValue, scrollContentHeightSharedValue]); const innerOnLayout = React.useCallback(evt => { onLayout?.(evt); scrollLayoutHeightSharedValue.set(evt.nativeEvent.layout.height); }, [onLayout, scrollLayoutHeightSharedValue]); const innerOnContentSizeChange = React.useCallback((w, h) => { onContentSizeChange?.(w, h); scrollContentHeightSharedValue.set(h); }, [onContentSizeChange, scrollContentHeightSharedValue]); const refs = useMergeRefs([scrollRef, ref]); return /*#__PURE__*/_jsx(BottomSheetScrollGestureDetector, { scrollRef: scrollRef, scrollOffsetYSharedValue: scrollOffsetYSharedValue, scrollContentHeightSharedValue: scrollContentHeightSharedValue, scrollLayoutHeightSharedValue: scrollLayoutHeightSharedValue, inverted: inverted, children: /*#__PURE__*/_jsx(ScrollView, { ref: refs, onScroll: innerOnScroll, onContentSizeChange: innerOnContentSizeChange, onLayout: innerOnLayout, scrollEventThrottle: 1, ...p }) }); }; } export const FlashListScrollComponent = makeFlashListScrollComponent(false); export const InvertedFlashListScrollComponent = makeFlashListScrollComponent(true); //# sourceMappingURL=flash-list-scroll-component.js.map