Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit a2c25d5

Browse files
authored
fix: correct icon showing on certain phones when not pulled (#3939)
1 parent 1946157 commit a2c25d5

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

src/components/Layout/PullToRefresh/index.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useEffect, useRef, useState } from 'react';
44

55
const PullToRefresh = () => {
66
const router = useRouter();
7-
87
const [pullStartPoint, setPullStartPoint] = useState(0);
98
const [pullChange, setPullChange] = useState(0);
109
const refreshDiv = useRef<HTMLDivElement>(null);
@@ -19,6 +18,7 @@ const PullToRefresh = () => {
1918
// Reload function that is called when reload threshold has been hit
2019
// Add loading class to determine when to add spin animation
2120
const forceReload = () => {
21+
setPullStartPoint(0);
2222
refreshDiv.current?.classList.add('loading');
2323
setTimeout(() => {
2424
router.reload();
@@ -32,6 +32,8 @@ const PullToRefresh = () => {
3232
const pullStart = (e: TouchEvent) => {
3333
setPullStartPoint(e.targetTouches[0].screenY);
3434

35+
const html = document.querySelector('html');
36+
3537
if (window.scrollY === 0 && window.scrollX === 0) {
3638
refreshDiv.current?.classList.add('block');
3739
refreshDiv.current?.classList.remove('hidden');
@@ -41,6 +43,7 @@ const PullToRefresh = () => {
4143
html.style.overscrollBehaviorY = 'none';
4244
}
4345
} else {
46+
setPullStartPoint(0);
4447
refreshDiv.current?.classList.remove('block');
4548
refreshDiv.current?.classList.add('hidden');
4649
}
@@ -49,7 +52,6 @@ const PullToRefresh = () => {
4952
// Tracks how far we have pulled down the refresh icon
5053
const pullDown = async (e: TouchEvent) => {
5154
const screenY = e.targetTouches[0].screenY;
52-
5355
const pullLength =
5456
pullStartPoint < screenY ? Math.abs(screenY - pullStartPoint) : 0;
5557

@@ -59,12 +61,11 @@ const PullToRefresh = () => {
5961
// Will reload the page if we are past the threshold
6062
// Otherwise, we reset the pull
6163
const pullFinish = () => {
62-
setPullStartPoint(0);
63-
64-
if (pullDownReloadThreshold) {
64+
if (pullDownReloadThreshold && pullStartPoint !== 0) {
6565
forceReload();
6666
} else {
6767
setPullChange(0);
68+
setTimeout(() => setPullStartPoint(0), 200);
6869
}
6970

7071
document.body.style.touchAction = 'auto';
@@ -83,7 +84,21 @@ const PullToRefresh = () => {
8384
window.removeEventListener('touchmove', pullDown);
8485
window.removeEventListener('touchend', pullFinish);
8586
};
86-
}, [pullDownInitThreshold, pullDownReloadThreshold, pullStartPoint, router]);
87+
}, [
88+
pullDownInitThreshold,
89+
pullDownReloadThreshold,
90+
pullStartPoint,
91+
refreshDiv,
92+
router,
93+
setPullStartPoint,
94+
]);
95+
96+
if (
97+
pullStartPoint === 0 &&
98+
!refreshDiv.current?.classList.contains('loading')
99+
) {
100+
return null;
101+
}
87102

88103
return (
89104
<div
@@ -102,7 +117,7 @@ const PullToRefresh = () => {
102117
<div
103118
className={`${
104119
refreshDiv.current?.classList.contains('loading') && 'animate-spin'
105-
} relative -top-24 h-9 w-9 rounded-full border-4 border-gray-800 bg-gray-800 shadow-md shadow-black ring-1 ring-gray-700`}
120+
} relative -top-28 h-9 w-9 rounded-full border-4 border-gray-800 bg-gray-800 shadow-md shadow-black ring-1 ring-gray-700`}
106121
style={{ animationDirection: 'reverse' }}
107122
>
108123
<ArrowPathIcon

0 commit comments

Comments
 (0)