A drawer component for React.
Fix incorrect offset when content is scrolled on iOS safari (#35)
Emil Kowalski817d09967747
diff --git a/src/context.ts b/src/context.tsindex ef276ac..48bcaec 100644--- a/src/context.ts+++ b/src/context.ts@@ -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>;}diff --git a/src/index.tsx b/src/index.tsxindex cb6cb58..6012a55 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -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;@@ -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);@@ -117,7 +118,7 @@ function Root({const initialViewportHeight = React.useRef(0);usePreventScroll({- isDisabled: !isOpen || isDragging,+ isDisabled: !isOpen || isDragging || isAnimating,});function getScale() {@@ -482,6 +483,7 @@ function Root({onNestedOpenChange,onNestedRelease,keyboardIsOpen,+ setIsAnimating,}}>{children}@@ -507,8 +509,17 @@ 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);@@ -516,7 +527,10 @@ const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (<DialogPrimitive.ContentonAnimationStart={(e) => {window.clearTimeout(animationEndTimer.current);+ setIsAnimating(true);+animationEndTimer.current = setTimeout(() => {+ setIsAnimating(false);onAnimationEnd?.(isOpen);}, ANIMATION_DURATION);onAnimationStart(e);diff --git a/website/src/app/components/hero.tsx b/website/src/app/components/hero.tsxindex 0582355..a76b4d9 100644--- a/website/src/app/components/hero.tsx+++ b/website/src/app/components/hero.tsx@@ -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"@@ -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"diff --git a/website/src/app/globals.css b/website/src/app/globals.cssindex 875c8f4..3017968 100644--- a/website/src/app/globals.css+++ b/website/src/app/globals.css@@ -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 {