Skip to content

Commit

Permalink
fix closeThreshold bug (#32)
Browse files Browse the repository at this point in the history
* add scroll lock timeout option and fix endless drag prevent

* remove debug type

* fix closeThreshold bug

* clean up a bit
  • Loading branch information
Gumbee authored Aug 7, 2023
1 parent 8804542 commit 8336f45
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import './style.css';
import { usePreventScroll, isInput } from './use-prevent-scroll';
import { useComposedRefs } from './use-composed-refs';

const CLOSE_TRESHOLD = 0.75;
const CLOSE_TRESHOLD = 0.25;
const SCROLL_LOCK_TIMEOUT = 1000;

const TRANSITIONS = {
Expand Down Expand Up @@ -349,10 +349,10 @@ function Root({
setIsDragging(false);
dragEndTime.current = new Date();
const swipeAmount = drawerRef.current
? getComputedStyle(drawerRef.current).getPropertyValue('--swipe-amount').slice(0, -2)
? Number.parseInt(getComputedStyle(drawerRef.current).getPropertyValue('--swipe-amount').slice(0, -2), 10)
: null;

if (!shouldDrag(event.target, false) || !swipeAmount) return;
if (!shouldDrag(event.target, false) || !swipeAmount || Number.isNaN(swipeAmount)) return;

if (dragStartTime.current === null) return;

Expand All @@ -375,7 +375,9 @@ function Root({
return;
}

if (y > window.innerHeight * closeTreshold) {
const visibleDrawerHeight = Math.min(drawerRef.current?.getBoundingClientRect().height || 0, window.innerHeight);

if (swipeAmount >= visibleDrawerHeight * closeTreshold) {
closeDrawer();
onReleaseProp?.(event, false);
return;
Expand Down

0 comments on commit 8336f45

Please sign in to comment.