@attio/react-native-bottom-sheet-toolbox
Version:
84 lines (83 loc) • 2.82 kB
JavaScript
;
import * as React from "react";
import { useMergeRefs } from "react-merge-refs";
import Animated from "react-native-reanimated";
import { BottomSheetScrollGestureDetector, useBottomSheetScrollGestureDetectorConnector } from "../bottom-sheet-scroll-gesture-detector";
import { BottomSheetListWrapper } from "./bottom-sheet-list-wrapper";
import { jsx as _jsx } from "react/jsx-runtime";
function makeBottomSheetFlatList(inverted) {
return function BottomSheetFlatList({
onScroll,
onBeginDrag,
onEndDrag,
onMomentumBegin,
onMomentumEnd,
onContentSizeChange,
ref,
onLayout,
...rest
}) {
const {
scrollHandler,
scrollOffsetYSharedValue,
scrollContentHeightSharedValue,
scrollLayoutHeightSharedValue,
scrollRef
} = useBottomSheetScrollGestureDetectorConnector({
...(onScroll && {
onScroll
}),
...(onBeginDrag && {
onBeginDrag
}),
...(onEndDrag && {
onEndDrag
}),
...(onMomentumBegin && {
onMomentumBegin
}),
...(onMomentumEnd && {
onMomentumEnd
})
});
const refs = useMergeRefs([scrollRef, ref]);
const innerOnContentSizeChange = React.useCallback((w, h) => {
if (typeof onContentSizeChange === "function") {
onContentSizeChange(w, h);
} else if (onContentSizeChange?.value) {
onContentSizeChange.value(w, h);
}
scrollContentHeightSharedValue.set(h);
}, [onContentSizeChange, scrollContentHeightSharedValue]);
const innerOnLayout = React.useCallback(evt => {
if (typeof onLayout === "function") {
onLayout(evt);
} else if (onLayout?.value) {
onLayout.value(evt);
}
scrollLayoutHeightSharedValue.set(evt.nativeEvent.layout.height);
}, [onLayout, scrollLayoutHeightSharedValue]);
return /*#__PURE__*/_jsx(BottomSheetScrollGestureDetector, {
scrollRef: scrollRef,
scrollOffsetYSharedValue: scrollOffsetYSharedValue,
scrollContentHeightSharedValue: scrollContentHeightSharedValue,
scrollLayoutHeightSharedValue: scrollLayoutHeightSharedValue,
inverted: inverted,
children: /*#__PURE__*/_jsx(BottomSheetListWrapper, {
contentHeightSharedValue: scrollContentHeightSharedValue,
children: /*#__PURE__*/_jsx(Animated.FlatList, {
ref: refs,
bounces: false,
scrollEventThrottle: 1,
onScroll: scrollHandler,
onContentSizeChange: innerOnContentSizeChange,
onLayout: innerOnLayout,
...rest
})
})
});
};
}
export const BottomSheetFlatList = makeBottomSheetFlatList(false);
export const InvertedBottomSheetFlatList = makeBottomSheetFlatList(true);
//# sourceMappingURL=bottom-sheet-flat-list.js.map