Skip to content

Commit

Permalink
Merge pull request #71 from thomasKn/thomas/fv-279-fix-header-animati…
Browse files Browse the repository at this point in the history
…on-on-drawer-close

Fix header animation on close Drawer
  • Loading branch information
thomasKn authored Feb 13, 2024
2 parents deb25a7 + 15bf217 commit 374afb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 9 additions & 12 deletions app/components/ui/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ import {IconClose} from '../icons/IconClose';
import {iconButtonClass} from './Button';

const Drawer = ({
onOpenChange,
open,
preventScrollRestoration = false,
shouldScaleBackground = false,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => {
const handleOpen = React.useCallback((open: boolean) => {
const handleOpen = React.useCallback(($open: boolean) => {
if (!document) return;
const body = document.body;

if (!open) {
const timeout = setTimeout(() => {
body.removeAttribute('data-drawer-open');
clearTimeout(timeout);
}, 500);
if (!$open) {
body.removeAttribute('data-drawer-open');
return;
}

body.setAttribute('data-drawer-open', String(open));
body.setAttribute('data-drawer-open', String($open));
}, []);

React.useEffect(() => {
if (open !== undefined) handleOpen(open);
}, [open, handleOpen]);

return (
<DrawerPrimitive.Root
onOpenChange={handleOpen}
onOpenChange={($open) => {
onOpenChange?.($open);
handleOpen($open);
}}
open={open}
preventScrollRestoration={preventScrollRestoration}
shouldScaleBackground={shouldScaleBackground}
Expand Down
6 changes: 2 additions & 4 deletions app/hooks/useBoundedScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export function useBoundedScroll(threshold: number) {
const body = document.body;
if (body.getAttribute('data-drawer-open') === 'true') return;

if (scrollYProgress.get() >= 0.95) {
// Reached the bottom of the page, so we don't want to bound the scroll
return;
}
// Reached the bottom of the page, so we don't want to bound the scroll
if (scrollYProgress.get() >= 0.95) return;

const previous = scrollY.getPrevious() ?? 0;
const diff = current - previous;
Expand Down

0 comments on commit 374afb9

Please sign in to comment.