Skip to content

armgit / vaul

Public Imported from GitHub
0

A drawer component for React.

Improve swipe performance (#50)

Emil Kowalski88578bb0bd51
diff --git a/src/index.tsx b/src/index.tsx
index a2a24a0..cc4c5a2 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -317,15 +317,13 @@ function Root({
function closeDrawer() {
if (!dismissible) return;
+ drawerRef.current.setAttribute('vaul-closed-by-dragging', 'true');
setIsOpen(false);
- const drawerHeight = drawerRef.current?.getBoundingClientRect().height || 0;
if (drawerRef.current) {
- const swipeAmount = getTranslateY(drawerRef.current);
-
set(drawerRef.current, {
- '--hide-from': `${Number(swipeAmount).toFixed()}px`,
- '--hide-to': `${drawerHeight.toFixed()}px`,
+ transform: `translateY(100%)`,
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
});
const opacityValue = overlayRef.current?.style.opacity || 1;
@@ -447,7 +445,7 @@ function Root({
transitionDuration: `${TRANSITIONS.DURATION}s`,
transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
});
- } else if (e.animationName === 'hide-dialog') {
+ } else if (e.animationName === 'hide-dialog' || e.animationName === 'fake-animation') {
// Exit
reset(wrapper, 'transform');
reset(wrapper, 'borderRadius');
diff --git a/src/style.css b/src/style.css
index dad6631..8f8e4c2 100644
--- a/src/style.css
+++ b/src/style.css
@@ -19,6 +19,10 @@
animation: hide-dialog 0.5s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}
+[vaul-drawer][vaul-closed-by-dragging='true'] {
+ animation: fake-animation 0.5s cubic-bezier(0.32, 0.72, 0, 1) forwards;
+}
+
[vaul-overlay] {
animation: show-overlay 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}
@@ -27,6 +31,16 @@
animation: hide-overlay 0.5s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}
+/* This will allow us to not animate via animation, but still benefit from delaying unmount via Radix. */
+@keyframes fake-animation {
+ from {
+ opacity: 1;
+ }
+ to {
+ opacity: 1;
+ }
+}
+
@keyframes show-dialog {
from {
transform: translateY(100%);