This commit is contained in:
@@ -95,6 +95,22 @@ export function BottomSheet({
|
||||
return () => document.removeEventListener('keydown', handleEscape);
|
||||
}, [isOpen, handleEscape]);
|
||||
|
||||
// Register with the global Android back-button stack so the
|
||||
// hardware back key closes the topmost open sheet. Non-dismissible
|
||||
// sheets opt out. Shared LIFO stack is keyed on `window`.
|
||||
useEffect(() => {
|
||||
if (!isOpen || !dismissible) return;
|
||||
if (typeof window === 'undefined') return;
|
||||
const g = window as any;
|
||||
if (!g.__brycordBackStack) g.__brycordBackStack = [];
|
||||
const stack: Array<() => void> = g.__brycordBackStack;
|
||||
stack.push(onClose);
|
||||
return () => {
|
||||
const i = stack.lastIndexOf(onClose);
|
||||
if (i !== -1) stack.splice(i, 1);
|
||||
};
|
||||
}, [isOpen, dismissible, onClose]);
|
||||
|
||||
// Lock body scroll while the sheet is open — keeps the underlying page
|
||||
// from scrolling behind the drawer on mobile.
|
||||
useEffect(() => {
|
||||
|
||||
@@ -62,6 +62,23 @@ function ModalRoot({ isOpen, onClose, size = 'small', children, className, zInde
|
||||
return () => document.removeEventListener('keydown', handleEscape);
|
||||
}, [isOpen, handleEscape]);
|
||||
|
||||
// Register with the global back-handler stack so Android hardware
|
||||
// back closes the topmost open modal (shared across packages via
|
||||
// `window.__brycordBackStack`). No-op on environments without a
|
||||
// window (SSR / tests).
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
if (typeof window === 'undefined') return;
|
||||
const g = window as any;
|
||||
if (!g.__brycordBackStack) g.__brycordBackStack = [];
|
||||
const stack: Array<() => void> = g.__brycordBackStack;
|
||||
stack.push(onClose);
|
||||
return () => {
|
||||
const i = stack.lastIndexOf(onClose);
|
||||
if (i !== -1) stack.splice(i, 1);
|
||||
};
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
return createPortal(
|
||||
<AnimatePresence>
|
||||
{isOpen && (
|
||||
|
||||
Reference in New Issue
Block a user