UNPKG

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

Version:
55 lines (54 loc) 1.89 kB
"use strict"; import React from "react"; import { BottomSheetToolboxBackdropProvider, BottomSheetToolboxInternalProvider } from "@attio/react-native-bottom-sheet-toolbox"; import { useBottomSheetToolboxStackContext } from "./context/bottom-sheet-toolbox-stack-context"; import { jsx as _jsx } from "react/jsx-runtime"; export function BottomSheetToolboxStackSheet({ name, children, sheetRef, isReady }) { const { sheetStack, activeSheet, sheetRefsRef } = useBottomSheetToolboxStackContext(); const isMounted = sheetStack.includes(name); const isActive = activeSheet === name; const lastKnownSnapIndex = React.useRef(null); if (sheetRefsRef.current !== null && sheetRef.current !== null) { sheetRefsRef.current[name] = sheetRef.current; } React.useEffect(() => { if (isMounted) return; lastKnownSnapIndex.current = null; }, [isMounted]); const lastIsActiveRef = React.useRef(isActive); React.useEffect(() => { if (!isReady) return; const lastIsActive = lastIsActiveRef.current; if (lastIsActive && !isActive) { const snapIndex = sheetRef.current?.getCurrentSnapIndex() || null; lastKnownSnapIndex.current = snapIndex; sheetRef.current?.close(); } else if (!lastIsActive && isActive) { if (lastKnownSnapIndex.current !== null) { if (lastKnownSnapIndex.current === 0) { sheetRef.current?.expand(); } else { sheetRef.current?.snapToIndex(lastKnownSnapIndex.current); } } } lastIsActiveRef.current = isActive; }, [isActive, sheetRef, isReady]); return isMounted ? /*#__PURE__*/_jsx(BottomSheetToolboxBackdropProvider, { hide: !isActive, children: /*#__PURE__*/_jsx(BottomSheetToolboxInternalProvider, { reset: true, children: children }) }) : null; } //# sourceMappingURL=bottom-sheet-toolbox-stack-sheet.js.map