mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
Refactor scroll locking in ConnectionModal and TopUpModal: simplify the implementation by removing unnecessary style manipulations and enhancing event listeners for touch and wheel scroll prevention, ensuring a smoother user experience across devices.
This commit is contained in:
@@ -237,53 +237,31 @@ export default function ConnectionModal({ onClose }: ConnectionModalProps) {
|
|||||||
modalContentRef.current?.scrollTo({ top: 0, behavior: 'instant' })
|
modalContentRef.current?.scrollTo({ top: 0, behavior: 'instant' })
|
||||||
}, [showAppSelector])
|
}, [showAppSelector])
|
||||||
|
|
||||||
// Scroll lock when modal is open (cross-platform including Android)
|
// Scroll lock when modal is open
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const scrollY = window.scrollY
|
const scrollY = window.scrollY
|
||||||
const body = document.body
|
|
||||||
const html = document.documentElement
|
|
||||||
|
|
||||||
// Save original styles
|
// Prevent all touch/wheel scroll on backdrop
|
||||||
const originalStyles = {
|
|
||||||
bodyOverflow: body.style.overflow,
|
|
||||||
bodyPosition: body.style.position,
|
|
||||||
bodyTop: body.style.top,
|
|
||||||
bodyWidth: body.style.width,
|
|
||||||
bodyHeight: body.style.height,
|
|
||||||
htmlOverflow: html.style.overflow,
|
|
||||||
htmlHeight: html.style.height,
|
|
||||||
bodyTouchAction: body.style.touchAction,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lock scroll
|
|
||||||
body.style.overflow = 'hidden'
|
|
||||||
body.style.position = 'fixed'
|
|
||||||
body.style.top = `-${scrollY}px`
|
|
||||||
body.style.width = '100%'
|
|
||||||
body.style.height = '100%'
|
|
||||||
body.style.touchAction = 'none'
|
|
||||||
html.style.overflow = 'hidden'
|
|
||||||
html.style.height = '100%'
|
|
||||||
|
|
||||||
// Prevent touchmove on backdrop (Android fix)
|
|
||||||
const preventScroll = (e: TouchEvent) => {
|
const preventScroll = (e: TouchEvent) => {
|
||||||
const target = e.target as HTMLElement
|
const target = e.target as HTMLElement
|
||||||
// Allow scroll inside modal content
|
|
||||||
if (target.closest('[data-modal-content]')) return
|
if (target.closest('[data-modal-content]')) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const preventWheel = (e: WheelEvent) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
if (target.closest('[data-modal-content]')) return
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('touchmove', preventScroll, { passive: false })
|
document.addEventListener('touchmove', preventScroll, { passive: false })
|
||||||
|
document.addEventListener('wheel', preventWheel, { passive: false })
|
||||||
|
document.body.style.overflow = 'hidden'
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
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
|
|
||||||
body.style.touchAction = originalStyles.bodyTouchAction
|
|
||||||
html.style.overflow = originalStyles.htmlOverflow
|
|
||||||
html.style.height = originalStyles.htmlHeight
|
|
||||||
document.removeEventListener('touchmove', preventScroll)
|
document.removeEventListener('touchmove', preventScroll)
|
||||||
|
document.removeEventListener('wheel', preventWheel)
|
||||||
|
document.body.style.overflow = ''
|
||||||
window.scrollTo(0, scrollY)
|
window.scrollTo(0, scrollY)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@@ -55,52 +55,31 @@ export default function TopUpModal({ method, onClose, initialAmountRubles }: Top
|
|||||||
)
|
)
|
||||||
const popupRef = useRef<Window | null>(null)
|
const popupRef = useRef<Window | null>(null)
|
||||||
|
|
||||||
// Scroll lock when modal is open (cross-platform including Android)
|
// Scroll lock when modal is open
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const scrollY = window.scrollY
|
const scrollY = window.scrollY
|
||||||
const body = document.body
|
|
||||||
const html = document.documentElement
|
|
||||||
|
|
||||||
// Save original styles
|
// Prevent all touch/wheel scroll on backdrop
|
||||||
const originalStyles = {
|
|
||||||
bodyOverflow: body.style.overflow,
|
|
||||||
bodyPosition: body.style.position,
|
|
||||||
bodyTop: body.style.top,
|
|
||||||
bodyWidth: body.style.width,
|
|
||||||
bodyHeight: body.style.height,
|
|
||||||
htmlOverflow: html.style.overflow,
|
|
||||||
htmlHeight: html.style.height,
|
|
||||||
bodyTouchAction: body.style.touchAction,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lock scroll
|
|
||||||
body.style.overflow = 'hidden'
|
|
||||||
body.style.position = 'fixed'
|
|
||||||
body.style.top = `-${scrollY}px`
|
|
||||||
body.style.width = '100%'
|
|
||||||
body.style.height = '100%'
|
|
||||||
body.style.touchAction = 'none'
|
|
||||||
html.style.overflow = 'hidden'
|
|
||||||
html.style.height = '100%'
|
|
||||||
|
|
||||||
// Prevent touchmove on backdrop (Android fix)
|
|
||||||
const preventScroll = (e: TouchEvent) => {
|
const preventScroll = (e: TouchEvent) => {
|
||||||
const target = e.target as HTMLElement
|
const target = e.target as HTMLElement
|
||||||
if (target.closest('[data-modal-content]')) return
|
if (target.closest('[data-modal-content]')) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const preventWheel = (e: WheelEvent) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
if (target.closest('[data-modal-content]')) return
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('touchmove', preventScroll, { passive: false })
|
document.addEventListener('touchmove', preventScroll, { passive: false })
|
||||||
|
document.addEventListener('wheel', preventWheel, { passive: false })
|
||||||
|
document.body.style.overflow = 'hidden'
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
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
|
|
||||||
body.style.touchAction = originalStyles.bodyTouchAction
|
|
||||||
html.style.overflow = originalStyles.htmlOverflow
|
|
||||||
html.style.height = originalStyles.htmlHeight
|
|
||||||
document.removeEventListener('touchmove', preventScroll)
|
document.removeEventListener('touchmove', preventScroll)
|
||||||
|
document.removeEventListener('wheel', preventWheel)
|
||||||
|
document.body.style.overflow = ''
|
||||||
window.scrollTo(0, scrollY)
|
window.scrollTo(0, scrollY)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ export default function Layout({ children }: LayoutProps) {
|
|||||||
<div className="w-full mx-auto px-4 sm:px-6">
|
<div className="w-full mx-auto px-4 sm:px-6">
|
||||||
<div className="flex justify-between items-center h-16 lg:h-20">
|
<div className="flex justify-between items-center h-16 lg:h-20">
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
<Link to="/" className={`flex items-center gap-2.5 flex-shrink-0 ${!appName ? 'lg:mr-4' : ''}`}>
|
<Link to="/" onClick={() => setMobileMenuOpen(false)} className={`flex items-center gap-2.5 flex-shrink-0 ${!appName ? 'lg:mr-4' : ''}`}>
|
||||||
<div className="w-10 h-10 sm:w-12 sm:h-12 lg:w-14 lg:h-14 rounded-xl bg-gradient-to-br from-accent-400 to-accent-600 flex items-center justify-center overflow-hidden shadow-lg shadow-accent-500/20 flex-shrink-0 relative">
|
<div className="w-10 h-10 sm:w-12 sm:h-12 lg:w-14 lg:h-14 rounded-xl bg-gradient-to-br from-accent-400 to-accent-600 flex items-center justify-center overflow-hidden shadow-lg shadow-accent-500/20 flex-shrink-0 relative">
|
||||||
{/* Always show letter as fallback */}
|
{/* Always show letter as fallback */}
|
||||||
<span className={`text-white font-bold text-lg sm:text-xl lg:text-2xl absolute transition-opacity duration-200 ${hasCustomLogo && logoLoaded ? 'opacity-0' : 'opacity-100'}`}>
|
<span className={`text-white font-bold text-lg sm:text-xl lg:text-2xl absolute transition-opacity duration-200 ${hasCustomLogo && logoLoaded ? 'opacity-0' : 'opacity-100'}`}>
|
||||||
@@ -435,7 +435,10 @@ export default function Layout({ children }: LayoutProps) {
|
|||||||
{/* Theme toggle button - only show if both themes are enabled */}
|
{/* Theme toggle button - only show if both themes are enabled */}
|
||||||
{canToggle && (
|
{canToggle && (
|
||||||
<button
|
<button
|
||||||
onClick={toggleTheme}
|
onClick={() => {
|
||||||
|
toggleTheme()
|
||||||
|
setMobileMenuOpen(false)
|
||||||
|
}}
|
||||||
className="relative p-2.5 rounded-xl transition-all duration-300 hover:scale-110 active:scale-95
|
className="relative p-2.5 rounded-xl transition-all duration-300 hover:scale-110 active:scale-95
|
||||||
dark:text-dark-400 dark:hover:text-dark-100 dark:hover:bg-dark-800
|
dark:text-dark-400 dark:hover:text-dark-100 dark:hover:bg-dark-800
|
||||||
text-champagne-500 hover:text-champagne-800 hover:bg-champagne-200/50"
|
text-champagne-500 hover:text-champagne-800 hover:bg-champagne-200/50"
|
||||||
@@ -453,10 +456,14 @@ export default function Layout({ children }: LayoutProps) {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PromoDiscountBadge />
|
<div onClick={() => setMobileMenuOpen(false)}>
|
||||||
<TicketNotificationBell isAdmin={isAdminActive()} />
|
<PromoDiscountBadge />
|
||||||
|
</div>
|
||||||
|
<div onClick={() => setMobileMenuOpen(false)}>
|
||||||
|
<TicketNotificationBell isAdmin={isAdminActive()} />
|
||||||
|
</div>
|
||||||
{/* Hide language switcher on mobile when promo is active */}
|
{/* Hide language switcher on mobile when promo is active */}
|
||||||
<div className={isPromoActive ? 'hidden sm:block' : ''}>
|
<div className={isPromoActive ? 'hidden sm:block' : ''} onClick={() => setMobileMenuOpen(false)}>
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user