|
|
@ -10,7 +10,6 @@ let initialHtmlOverflow = ""; |
|
|
let initialAppShellOverflow = ""; |
|
|
let initialAppShellOverflow = ""; |
|
|
let initialAppShellTouchAction = ""; |
|
|
let initialAppShellTouchAction = ""; |
|
|
let lockedAppShell: HTMLElement | null = null; |
|
|
let lockedAppShell: HTMLElement | null = null; |
|
|
const SHEET_HISTORY_KEY = "__habibQuestionSheet"; |
|
|
|
|
|
|
|
|
|
|
|
type SheetScrollLockOptions = { |
|
|
type SheetScrollLockOptions = { |
|
|
onBack?: () => void; |
|
|
onBack?: () => void; |
|
|
@ -25,7 +24,7 @@ export function useSheetScrollLock( |
|
|
onBackRef.current = onBack; |
|
|
onBackRef.current = onBack; |
|
|
|
|
|
|
|
|
// Register in the hardware-back handler stack so that Flutter's
|
|
|
// Register in the hardware-back handler stack so that Flutter's
|
|
|
// __habibHandleHardwareBack() closes the sheet instead of navigating.
|
|
|
|
|
|
|
|
|
// __habibHandleHardwareBackSync() closes the sheet instead of exiting the screen.
|
|
|
const handleHardwareBack = useCallback(() => { |
|
|
const handleHardwareBack = useCallback(() => { |
|
|
if (onBackRef.current) { |
|
|
if (onBackRef.current) { |
|
|
onBackRef.current(); |
|
|
onBackRef.current(); |
|
|
@ -39,18 +38,6 @@ export function useSheetScrollLock( |
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
if (!isOpen) return; |
|
|
if (!isOpen) return; |
|
|
|
|
|
|
|
|
const historyState = window.history.state; |
|
|
|
|
|
const ownsHistoryEntry = |
|
|
|
|
|
historyState?.[SHEET_HISTORY_KEY] !== true && activeSheetCount === 0; |
|
|
|
|
|
|
|
|
|
|
|
if (ownsHistoryEntry) { |
|
|
|
|
|
window.history.pushState( |
|
|
|
|
|
{ ...(historyState ?? {}), [SHEET_HISTORY_KEY]: true }, |
|
|
|
|
|
"", |
|
|
|
|
|
window.location.href, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (activeSheetCount === 0) { |
|
|
if (activeSheetCount === 0) { |
|
|
bodyHadDropdownClass = document.body.classList.contains("dropdown-open"); |
|
|
bodyHadDropdownClass = document.body.classList.contains("dropdown-open"); |
|
|
initialBodyOverflow = document.body.style.overflow; |
|
|
initialBodyOverflow = document.body.style.overflow; |
|
|
@ -70,23 +57,9 @@ export function useSheetScrollLock( |
|
|
lockedAppShell.style.touchAction = "none"; |
|
|
lockedAppShell.style.touchAction = "none"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const handlePopState = () => { |
|
|
|
|
|
if (ownsHistoryEntry) { |
|
|
|
|
|
onBackRef.current?.(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
window.addEventListener("popstate", handlePopState); |
|
|
|
|
|
|
|
|
|
|
|
return () => { |
|
|
return () => { |
|
|
window.removeEventListener("popstate", handlePopState); |
|
|
|
|
|
activeSheetCount = Math.max(0, activeSheetCount - 1); |
|
|
activeSheetCount = Math.max(0, activeSheetCount - 1); |
|
|
if (activeSheetCount === 0) { |
|
|
if (activeSheetCount === 0) { |
|
|
if ( |
|
|
|
|
|
ownsHistoryEntry && |
|
|
|
|
|
window.history.state?.[SHEET_HISTORY_KEY] === true |
|
|
|
|
|
) { |
|
|
|
|
|
window.history.back(); |
|
|
|
|
|
} |
|
|
|
|
|
document.body.style.overflow = initialBodyOverflow; |
|
|
document.body.style.overflow = initialBodyOverflow; |
|
|
document.documentElement.style.overflow = initialHtmlOverflow; |
|
|
document.documentElement.style.overflow = initialHtmlOverflow; |
|
|
if (lockedAppShell) { |
|
|
if (lockedAppShell) { |
|
|
|