UNPKG

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

Version:
61 lines (60 loc) 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvertedFlashListScrollComponent = exports.FlashListScrollComponent = void 0; var React = _interopRequireWildcard(require("react")); var _reactMergeRefs = require("react-merge-refs"); var _reactNative = require("react-native"); var _reactNativeBottomSheetToolbox = require("@attio/react-native-bottom-sheet-toolbox"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function makeFlashListScrollComponent(inverted) { return function FlashListScrollComponent({ onScroll, onLayout, onContentSizeChange, ref, ...p }) { const { scrollOffsetYSharedValue, scrollRef, scrollContentHeightSharedValue, scrollLayoutHeightSharedValue } = (0, _reactNativeBottomSheetToolbox.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 = (0, _reactMergeRefs.useMergeRefs)([scrollRef, ref]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeBottomSheetToolbox.BottomSheetScrollGestureDetector, { scrollRef: scrollRef, scrollOffsetYSharedValue: scrollOffsetYSharedValue, scrollContentHeightSharedValue: scrollContentHeightSharedValue, scrollLayoutHeightSharedValue: scrollLayoutHeightSharedValue, inverted: inverted, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, { ref: refs, onScroll: innerOnScroll, onContentSizeChange: innerOnContentSizeChange, onLayout: innerOnLayout, scrollEventThrottle: 1, ...p }) }); }; } const FlashListScrollComponent = exports.FlashListScrollComponent = makeFlashListScrollComponent(false); const InvertedFlashListScrollComponent = exports.InvertedFlashListScrollComponent = makeFlashListScrollComponent(true); //# sourceMappingURL=flash-list-scroll-component.js.map