fix: prevent pull-to-refresh from triggering on unexpected scroll positions (#2419)

This commit is contained in:
soxa 2025-08-13 20:31:49 +02:00 committed by GitHub
parent 3feb4f055f
commit 0394a5bdc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,6 +17,13 @@ export default function PullToRefresh ({ children, className }) {
setIsPWA(androidPWA || iosPWA)
}
const clearPullDistance = () => {
setPullDistance(0)
document.body.style.marginTop = '0px'
touchStartY.current = 0
touchEndY.current = 0
}
useEffect(checkPWA, [])
const handleTouchStart = useCallback((e) => {
@ -28,6 +35,13 @@ export default function PullToRefresh ({ children, className }) {
const handleTouchMove = useCallback((e) => {
if (touchStartY.current === 0) return
if (!isPWA) return
// if we're not at the top of the page after the touch start, reset the pull distance
if (window.scrollY > 0) {
clearPullDistance()
return
}
touchEndY.current = e.touches[0].clientY
const distance = touchEndY.current - touchStartY.current
setPullDistance(distance)
@ -39,10 +53,7 @@ export default function PullToRefresh ({ children, className }) {
if (touchEndY.current - touchStartY.current > REFRESH_THRESHOLD) {
router.push(router.asPath)
}
setPullDistance(0)
document.body.style.marginTop = '0px'
touchStartY.current = 0
touchEndY.current = 0
clearPullDistance()
}, [router])
useEffect(() => {