UNPKG

@crossed/sheet

Version:

A Cross Platform(Android & iOS) ActionSheet with a robust and flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.

85 lines (84 loc) 2.3 kB
import { jsx } from "react/jsx-runtime"; import React, { useImperativeHandle } from "react"; import { SectionList as RNSectionList } from "react-native"; import { ScrollView } from "react-native-gesture-handler"; import { useScrollHandlers } from "../hooks/use-scroll-handlers"; import { nativeViewProps } from "react-native-gesture-handler/src/handlers/NativeViewGestureHandler"; const RNGHSectionList = (props, ref) => { const refreshControlGestureRef = React.useRef(null); const { waitFor, refreshControl, ...rest } = props; const flatListProps = {}; const scrollViewProps = {}; for (const [propName, value] of Object.entries(rest)) { if (nativeViewProps.includes(propName)) { scrollViewProps[propName] = value; } else { flatListProps[propName] = value; } } return /* @__PURE__ */ jsx( RNSectionList, { ref, ...flatListProps, scrollEventThrottle: 1, renderScrollComponent: (scrollProps) => /* @__PURE__ */ jsx( ScrollView, { ...{ ...scrollProps, ...scrollViewProps, waitFor: [...toArray(waitFor ?? []), refreshControlGestureRef] } } ), refreshControl: refreshControl ? React.cloneElement(refreshControl, { ref: refreshControlGestureRef }) : void 0 } ); }; function $SectionList(props, ref) { const handlers = useScrollHandlers({ hasRefreshControl: !!props.refreshControl, refreshControlBoundary: props.refreshControlGestureArea || 0.15 }); useImperativeHandle(ref, () => handlers.ref); return /* @__PURE__ */ jsx( RNGHSectionList, { ...props, ...handlers, onScroll: (event) => { var _a; handlers.onScroll(event); (_a = props.onScroll) == null ? void 0 : _a.call(props, event); }, bounces: false, onLayout: (event) => { var _a; handlers.onLayout(); (_a = props.onLayout) == null ? void 0 : _a.call(props, event); }, scrollEventThrottle: 1 } ); } const SectionList = React.forwardRef( $SectionList ); function toArray(object) { if (!Array.isArray(object)) { return [object]; } return object; } export { RNGHSectionList, SectionList }; //# sourceMappingURL=SectionList.js.map