@attio/react-native-bottom-sheet-toolbox-stack
Version:
60 lines (59 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BottomSheetToolboxStackSheet = BottomSheetToolboxStackSheet;
var _react = _interopRequireDefault(require("react"));
var _reactNativeBottomSheetToolbox = require("@attio/react-native-bottom-sheet-toolbox");
var _bottomSheetToolboxStackContext = require("./context/bottom-sheet-toolbox-stack-context");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function BottomSheetToolboxStackSheet({
name,
children,
sheetRef,
isReady
}) {
const {
sheetStack,
activeSheet,
sheetRefsRef
} = (0, _bottomSheetToolboxStackContext.useBottomSheetToolboxStackContext)();
const isMounted = sheetStack.includes(name);
const isActive = activeSheet === name;
const lastKnownSnapIndex = _react.default.useRef(null);
if (sheetRefsRef.current !== null && sheetRef.current !== null) {
sheetRefsRef.current[name] = sheetRef.current;
}
_react.default.useEffect(() => {
if (isMounted) return;
lastKnownSnapIndex.current = null;
}, [isMounted]);
const lastIsActiveRef = _react.default.useRef(isActive);
_react.default.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__*/(0, _jsxRuntime.jsx)(_reactNativeBottomSheetToolbox.BottomSheetToolboxBackdropProvider, {
hide: !isActive,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeBottomSheetToolbox.BottomSheetToolboxInternalProvider, {
reset: true,
children: children
})
}) : null;
}
//# sourceMappingURL=bottom-sheet-toolbox-stack-sheet.js.map