chore: fix scroll in mobile popovers [skip e2e]
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile'
|
import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile'
|
||||||
import { classNames } from '@standardnotes/snjs'
|
import { classNames } from '@standardnotes/snjs'
|
||||||
import { ReactNode, useCallback, useEffect, useRef } from 'react'
|
import { ReactNode, useCallback, useEffect } from 'react'
|
||||||
import Portal from '../Portal/Portal'
|
import Portal from '../Portal/Portal'
|
||||||
import MobileModalAction from '../Modal/MobileModalAction'
|
import MobileModalAction from '../Modal/MobileModalAction'
|
||||||
import { MobileModalAnimationOptions, useModalAnimation } from '../Modal/useModalAnimation'
|
import { MobileModalAnimationOptions, useModalAnimation } from '../Modal/useModalAnimation'
|
||||||
@@ -10,6 +10,7 @@ import { DialogWithClose } from '@/Utils/CloseOpenModalsAndPopovers'
|
|||||||
import { useMediaQuery, MutuallyExclusiveMediaQueryBreakpoints } from '@/Hooks/useMediaQuery'
|
import { useMediaQuery, MutuallyExclusiveMediaQueryBreakpoints } from '@/Hooks/useMediaQuery'
|
||||||
import { SupportsPassiveListeners } from '@/Constants/Constants'
|
import { SupportsPassiveListeners } from '@/Constants/Constants'
|
||||||
import { useLifecycleAnimation } from '@/Hooks/useLifecycleAnimation'
|
import { useLifecycleAnimation } from '@/Hooks/useLifecycleAnimation'
|
||||||
|
import { getScrollParent } from '@/Utils'
|
||||||
|
|
||||||
const DisableScroll = () => {
|
const DisableScroll = () => {
|
||||||
useDisableBodyScrollOnMobile()
|
useDisableBodyScrollOnMobile()
|
||||||
@@ -61,15 +62,13 @@ const MobilePopoverContent = ({
|
|||||||
options: MobileModalAnimationOptions,
|
options: MobileModalAnimationOptions,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const scrollContainerRef = useRef<HTMLDivElement | null>(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const closestScrollContainer = scrollContainerRef.current
|
if (!element) {
|
||||||
|
|
||||||
if (!element || !closestScrollContainer) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let closestScrollContainer: HTMLElement | null = null
|
||||||
let elementY = 0
|
let elementY = 0
|
||||||
let startY = 0
|
let startY = 0
|
||||||
let startTimestamp = Date.now()
|
let startTimestamp = Date.now()
|
||||||
@@ -81,6 +80,7 @@ const MobilePopoverContent = ({
|
|||||||
startY = e.touches[0].clientY
|
startY = e.touches[0].clientY
|
||||||
elementY = element.getBoundingClientRect().y
|
elementY = element.getBoundingClientRect().y
|
||||||
startTimestamp = Date.now()
|
startTimestamp = Date.now()
|
||||||
|
closestScrollContainer = getScrollParent(e.target as HTMLElement)
|
||||||
closestScrollContainerScrollTop = closestScrollContainer?.scrollTop || 0
|
closestScrollContainerScrollTop = closestScrollContainer?.scrollTop || 0
|
||||||
isClosestScrollContainerScrolledAtStart = !!closestScrollContainer && closestScrollContainerScrollTop > 0
|
isClosestScrollContainerScrolledAtStart = !!closestScrollContainer && closestScrollContainerScrollTop > 0
|
||||||
containerScrollChangedAfterTouchStart = false
|
containerScrollChangedAfterTouchStart = false
|
||||||
@@ -105,7 +105,7 @@ const MobilePopoverContent = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const y = element.getBoundingClientRect().y
|
const y = element.getBoundingClientRect().y
|
||||||
if (y > elementY) {
|
if (y > elementY && closestScrollContainer) {
|
||||||
closestScrollContainer.style.overflowY = 'hidden'
|
closestScrollContainer.style.overflowY = 'hidden'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,9 @@ const MobilePopoverContent = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
startY = 0
|
startY = 0
|
||||||
closestScrollContainer.style.overflowY = ''
|
if (closestScrollContainer) {
|
||||||
|
closestScrollContainer.style.overflowY = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.addEventListener('touchstart', touchStartHandler, SupportsPassiveListeners ? { passive: true } : false)
|
element.addEventListener('touchstart', touchStartHandler, SupportsPassiveListeners ? { passive: true } : false)
|
||||||
@@ -199,12 +201,7 @@ const MobilePopoverContent = ({
|
|||||||
Done
|
Done
|
||||||
</MobileModalAction>
|
</MobileModalAction>
|
||||||
</MobileModalHeader>
|
</MobileModalHeader>
|
||||||
<div
|
<div className={classNames('h-full overflow-y-auto overscroll-none bg-passive-5', className)}>{children}</div>
|
||||||
className={classNames('h-full overflow-y-auto overscroll-none bg-passive-5', className)}
|
|
||||||
ref={scrollContainerRef}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Portal>
|
</Portal>
|
||||||
|
|||||||
Reference in New Issue
Block a user