Skip to content

Commit e7724b0

Browse files
committed
fix_refresh_android_pwa
1 parent 9bd36db commit e7724b0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

components/pull-to-refresh.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useRouter } from 'next/router'
22
import { useState, useRef, useEffect, useCallback, useMemo } from 'react'
33
import styles from './pull-to-refresh.module.css'
4+
import NProgress from 'nprogress'
45

56
const REFRESH_THRESHOLD = 150
67

@@ -41,7 +42,7 @@ export default function PullToRefresh ({ children, className }) {
4142
clearPullDistance()
4243
return
4344
}
44-
45+
e.preventDefault()
4546
touchEndY.current = e.touches[0].clientY
4647
const distance = touchEndY.current - touchStartY.current
4748
setPullDistance(distance)
@@ -51,16 +52,17 @@ export default function PullToRefresh ({ children, className }) {
5152
const handleTouchEnd = useCallback(() => {
5253
if (touchStartY.current === 0 || touchEndY.current === 0) return
5354
if (touchEndY.current - touchStartY.current > REFRESH_THRESHOLD) {
54-
router.push(router.asPath)
55+
NProgress.done()
56+
router.replace(router.asPath)
5557
}
5658
clearPullDistance()
5759
}, [router])
5860

5961
useEffect(() => {
6062
if (!isPWA) return
6163
document.body.style.overscrollBehaviorY = 'contain'
62-
document.addEventListener('touchstart', handleTouchStart)
63-
document.addEventListener('touchmove', handleTouchMove)
64+
document.addEventListener('touchstart', handleTouchStart, { passive: false })
65+
document.addEventListener('touchmove', handleTouchMove, { passive: false })
6466
document.addEventListener('touchend', handleTouchEnd)
6567
return () => {
6668
document.body.style.overscrollBehaviorY = ''

0 commit comments

Comments
 (0)