Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect offset when content is scrolled on iOS safari #35

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface DrawerContextValue {
onNestedRelease: (event: React.PointerEvent<HTMLDivElement>, open: boolean) => void;
dismissible: boolean;
isOpen: boolean;
setIsAnimating: (o: boolean) => void;
keyboardIsOpen: React.MutableRefObject<boolean>;
}

Expand Down
22 changes: 18 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const TRANSITIONS = {
EASE: [0.32, 0.72, 0, 1],
};

const ANIMATION_DURATION = 500;
const ANIMATION_DURATION = 501;

const BORDER_RADIUS = 8;

Expand Down Expand Up @@ -106,6 +106,7 @@ function Root({
onChange: onOpenChange,
});
const [isDragging, setIsDragging] = React.useState(false);
const [isAnimating, setIsAnimating] = React.useState(true);
const overlayRef = React.useRef<HTMLDivElement>(null);
const dragStartTime = React.useRef<Date | null>(null);
const dragEndTime = React.useRef<Date | null>(null);
Expand All @@ -117,7 +118,7 @@ function Root({
const initialViewportHeight = React.useRef(0);

usePreventScroll({
isDisabled: !isOpen || isDragging,
isDisabled: !isOpen || isDragging || isAnimating,
});

function getScale() {
Expand Down Expand Up @@ -482,6 +483,7 @@ function Root({
onNestedOpenChange,
onNestedRelease,
keyboardIsOpen,
setIsAnimating,
}}
>
{children}
Expand All @@ -507,16 +509,28 @@ const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (
{ children, onOpenAutoFocus, onPointerDownOutside, onAnimationEnd, ...rest },
ref,
) {
const { drawerRef, onPress, onRelease, onAnimationStart, onDrag, dismissible, isOpen, keyboardIsOpen } =
useDrawerContext();
const {
drawerRef,
onPress,
onRelease,
onAnimationStart,
onDrag,
dismissible,
isOpen,
keyboardIsOpen,
setIsAnimating,
} = useDrawerContext();
const composedRef = useComposedRefs(ref, drawerRef);
const animationEndTimer = React.useRef<NodeJS.Timeout>(null);

return (
<DialogPrimitive.Content
onAnimationStart={(e) => {
window.clearTimeout(animationEndTimer.current);
setIsAnimating(true);

animationEndTimer.current = setTimeout(() => {
setIsAnimating(false);
onAnimationEnd?.(isOpen);
}, ANIMATION_DURATION);
onAnimationStart(e);
Expand Down
12 changes: 6 additions & 6 deletions website/src/app/components/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export function Hero() {
fill="none"
height="16"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="16"
aria-hidden="true"
Expand All @@ -115,9 +115,9 @@ export function Hero() {
fill="none"
height="16"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="16"
aria-hidden="true"
Expand Down
8 changes: 4 additions & 4 deletions website/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

html,
body {
overflow: hidden;
/* overflow: hidden; */
}

body,
main {
min-height: 100vh;
min-height: 200vh;
/* mobile viewport bug fix */
min-height: -webkit-fill-available;
overflow-x: hidden;
/* min-height: -webkit-fill-available;
overflow-x: hidden; */
}

html {
Expand Down