UNPKG

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

Version:
42 lines (41 loc) 1.31 kB
"use strict"; import React from "react"; import { ModalPortal } from "./modal-portal"; import { jsx as _jsx } from "react/jsx-runtime"; export function BottomSheetModalWrapper({ ref, children, openSheetOnMount = false, onClose }) { const [isSheetOpen, setIsSheetOpen] = React.useState(openSheetOnMount); const openSheet = React.useCallback(() => setIsSheetOpen(true), []); const closeSheet = React.useCallback(() => setIsSheetOpen(false), []); const currentOnClose = React.useMemo(() => onClose ?? (() => {}), [onClose]); const onSheetClose = React.useCallback(() => { closeSheet(); currentOnClose(); }, [closeSheet, currentOnClose]); const innerRef = React.useRef(null); const closeSheetPreserveAnimation = React.useCallback(() => { if (innerRef.current) { innerRef.current.close(); } else { setIsSheetOpen(false); } }, []); React.useImperativeHandle(ref, () => ({ open: openSheet, close: closeSheetPreserveAnimation }), [openSheet, closeSheetPreserveAnimation]); return /*#__PURE__*/_jsx(ModalPortal, { visible: isSheetOpen, onDismiss: closeSheet, onRequestClose: closeSheet, children: children({ ref: innerRef, onClose: onSheetClose }) }); } //# sourceMappingURL=bottom-sheet-modal-wrapper.js.map