Skip to content

Commit

Permalink
feat: added shadow effects to icon
Browse files Browse the repository at this point in the history
  • Loading branch information
OwsleyJr committed Mar 22, 2023
1 parent 5eff7a2 commit 10c23b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
48 changes: 34 additions & 14 deletions src/components/Layout/PullToRefresh/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const PullToRefresh = () => {
const [unlockScreen, setUnlockScreen] = useState(true);
const refreshDiv = useRef<HTMLDivElement>(null);

const pullDownInitThreshold = pullChange > 20;
const pullDownStopThreshold = 120;
const pullDownReloadThreshold = pullChange > 340;
const pullDownIconLocation = pullChange / 3;

useEffect(() => {
const forceReload = () => {
refreshDiv.current?.classList.add('loading');
Expand All @@ -19,7 +24,14 @@ const PullToRefresh = () => {
}, 1000);
};

const html = document.querySelector('html');

if (html) {
html.style.overscrollBehaviorY = 'none';
}

const pullStart = (e: TouchEvent) => {
e.preventDefault();
setPullStartPoint(e.targetTouches[0].screenY);
};

Expand All @@ -34,7 +46,7 @@ const PullToRefresh = () => {
const pullFinish = () => {
setPullStartPoint(0);

if (pullChange > 240) {
if (pullDownReloadThreshold) {
forceReload();
} else {
setPullChange(0);
Expand All @@ -50,7 +62,13 @@ const PullToRefresh = () => {
window.removeEventListener('touchmove', pullDown);
window.removeEventListener('touchend', pullFinish);
};
}, [pullChange, pullStartPoint, router, unlockScreen]);
}, [
pullChange,
pullDownReloadThreshold,
pullStartPoint,
router,
unlockScreen,
]);

const isIconVisible = async (element: HTMLDivElement) => {
return new Promise((resolve) => {
Expand All @@ -68,7 +86,7 @@ const PullToRefresh = () => {
) as HTMLDivElement;

const checkIfVisible = async () => {
if (await isIconVisible(refreshIcon)) {
if ((await isIconVisible(refreshIcon)) && pullDownInitThreshold) {
setUnlockScreen(false);
} else {
setUnlockScreen(true);
Expand All @@ -80,32 +98,34 @@ const PullToRefresh = () => {
return () => {
window.removeEventListener('touchmove', checkIfVisible);
};
}, []);
}, [pullChange, pullDownInitThreshold]);

useLockBodyScroll(true, unlockScreen);

return (
<div
ref={refreshDiv}
className="absolute left-0 right-0 -top-16 z-50 m-auto w-fit transition-all ease-out"
className="absolute left-0 right-0 top-0 z-50 m-auto w-fit transition-all ease-out"
id="refreshIcon"
style={{
top:
pullChange / 3 < 80 && pullChange > 20
? pullChange / 3
: pullChange > 20
? 80
pullDownIconLocation < pullDownStopThreshold && pullDownInitThreshold
? pullDownIconLocation
: pullDownInitThreshold
? pullDownStopThreshold
: '',
}}
id="refreshIcon"
>
<div
className={`${
refreshDiv.current?.classList[9] === 'loading' && 'animate-spin'
} ${
pullChange > 240 ? 'rotate-180' : '-rotate-180'
} p-2 transition-all duration-300`}
} 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`}
>
<ArrowPathIcon className="h-9 w-9 rounded-full border-4 border-gray-800 bg-gray-800 text-indigo-500 ring-1 ring-gray-700" />
<ArrowPathIcon
className={`rounded-full ${
pullDownReloadThreshold && 'rotate-180'
} text-indigo-500 transition-all duration-300`}
/>
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
min-height: calc(100% + env(safe-area-inset-top));
padding: env(safe-area-inset-top) env(safe-area-inset-right)
calc(4rem + env(safe-area-inset-bottom)) env(safe-area-inset-left);
overscroll-behavior-y: none;
}

@media (min-width: 640px) {
Expand All @@ -18,7 +17,8 @@

body {
@apply bg-gray-900;
overscroll-behavior-y: none;
overscroll-behavior-y: contain;
-webkit-overflow-scrolling: touch;
}

code {
Expand Down

0 comments on commit 10c23b3

Please sign in to comment.