mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
Update Layout.tsx
This commit is contained in:
@@ -163,34 +163,25 @@ export default function Layout({ children }: LayoutProps) {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Lock body scroll when mobile menu is open (cross-platform)
|
// Lock body scroll when mobile menu is open (cross-platform)
|
||||||
|
// Note: We avoid using body position:fixed with top:-scrollY as it causes issues
|
||||||
|
// in Telegram Mini App where the menu disappears when opened from scrolled position
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!mobileMenuOpen) return
|
if (!mobileMenuOpen) return
|
||||||
|
|
||||||
const scrollY = window.scrollY
|
|
||||||
const body = document.body
|
const body = document.body
|
||||||
const html = document.documentElement
|
const html = document.documentElement
|
||||||
|
|
||||||
// Save original styles
|
// Save original styles
|
||||||
const originalStyles = {
|
const originalStyles = {
|
||||||
bodyOverflow: body.style.overflow,
|
bodyOverflow: body.style.overflow,
|
||||||
bodyPosition: body.style.position,
|
|
||||||
bodyTop: body.style.top,
|
|
||||||
bodyWidth: body.style.width,
|
|
||||||
bodyHeight: body.style.height,
|
|
||||||
htmlOverflow: html.style.overflow,
|
htmlOverflow: html.style.overflow,
|
||||||
htmlHeight: html.style.height,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock scroll - works on iOS, Android, and desktop
|
// Lock scroll - simple approach without body position manipulation
|
||||||
body.style.overflow = 'hidden'
|
body.style.overflow = 'hidden'
|
||||||
body.style.position = 'fixed'
|
|
||||||
body.style.top = `-${scrollY}px`
|
|
||||||
body.style.width = '100%'
|
|
||||||
body.style.height = '100%'
|
|
||||||
html.style.overflow = 'hidden'
|
html.style.overflow = 'hidden'
|
||||||
html.style.height = '100%'
|
|
||||||
|
|
||||||
// Prevent touchmove on body (extra protection for mobile)
|
// Prevent touchmove on body (critical for mobile, especially Telegram Mini App)
|
||||||
const preventScroll = (e: TouchEvent) => {
|
const preventScroll = (e: TouchEvent) => {
|
||||||
const target = e.target as HTMLElement
|
const target = e.target as HTMLElement
|
||||||
// Allow scroll inside menu content
|
// Allow scroll inside menu content
|
||||||
@@ -199,21 +190,22 @@ export default function Layout({ children }: LayoutProps) {
|
|||||||
}
|
}
|
||||||
document.addEventListener('touchmove', preventScroll, { passive: false })
|
document.addEventListener('touchmove', preventScroll, { passive: false })
|
||||||
|
|
||||||
|
// Also prevent wheel scroll on desktop
|
||||||
|
const preventWheel = (e: WheelEvent) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
if (target.closest('.mobile-menu-content')) return
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
document.addEventListener('wheel', preventWheel, { passive: false })
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
// Restore original styles
|
// Restore original styles
|
||||||
body.style.overflow = originalStyles.bodyOverflow
|
body.style.overflow = originalStyles.bodyOverflow
|
||||||
body.style.position = originalStyles.bodyPosition
|
|
||||||
body.style.top = originalStyles.bodyTop
|
|
||||||
body.style.width = originalStyles.bodyWidth
|
|
||||||
body.style.height = originalStyles.bodyHeight
|
|
||||||
html.style.overflow = originalStyles.htmlOverflow
|
html.style.overflow = originalStyles.htmlOverflow
|
||||||
html.style.height = originalStyles.htmlHeight
|
|
||||||
|
|
||||||
// Remove touchmove listener
|
// Remove listeners
|
||||||
document.removeEventListener('touchmove', preventScroll)
|
document.removeEventListener('touchmove', preventScroll)
|
||||||
|
document.removeEventListener('wheel', preventWheel)
|
||||||
// Restore scroll position
|
|
||||||
window.scrollTo(0, scrollY)
|
|
||||||
}
|
}
|
||||||
}, [mobileMenuOpen])
|
}, [mobileMenuOpen])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user