Skip to content

Commit 549ab30

Browse files
authored
fix: dragging can overshoot if onDismiss is undefined (stipsan#43)
1 parent 93decd5 commit 549ab30

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

package-lock.json

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BottomSheet.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export const BottomSheet = React.forwardRef<
6666
// Before any animations can start we need to measure a few things, like the viewport and the dimensions of content, and header + footer if they exist
6767
const { ready, registerReady } = useReady()
6868

69-
const dismissable = !!onDismiss
7069
// Controls the drag handler, used by spring operations that happen outside the render loop in React
7170
const canDragRef = useRef(false)
7271

@@ -438,12 +437,27 @@ export const BottomSheet = React.forwardRef<
438437
}
439438

440439
let newY = down
441-
? rubberbandIfOutOfBounds(
442-
rawY,
443-
onDismiss ? 0 : minSnapRef.current,
444-
maxSnapRef.current,
445-
0.55
446-
)
440+
? // @TODO figure out a better way to deal with rubberband overshooting if min and max have the same value
441+
!onDismiss && minSnapRef.current === maxSnapRef.current
442+
? rawY < minSnapRef.current
443+
? rubberbandIfOutOfBounds(
444+
rawY,
445+
minSnapRef.current,
446+
maxSnapRef.current * 2,
447+
0.55
448+
)
449+
: rubberbandIfOutOfBounds(
450+
rawY,
451+
minSnapRef.current / 2,
452+
maxSnapRef.current,
453+
0.55
454+
)
455+
: rubberbandIfOutOfBounds(
456+
rawY,
457+
onDismiss ? 0 : minSnapRef.current,
458+
maxSnapRef.current,
459+
0.55
460+
)
447461
: predictedY
448462

449463
if (first) {
@@ -489,7 +503,7 @@ export const BottomSheet = React.forwardRef<
489503
{...props}
490504
data-rsbs-root
491505
data-rsbs-is-blocking={blocking}
492-
data-rsbs-is-dismissable={dismissable}
506+
data-rsbs-is-dismissable={!!onDismiss}
493507
data-rsbs-has-header={!!header}
494508
data-rsbs-has-footer={!!footer}
495509
className={className}

0 commit comments

Comments
 (0)