Skip to content

Commit

Permalink
fix: dragging can overshoot if onDismiss is undefined (stipsan#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Dec 19, 2020
1 parent 93decd5 commit 549ab30
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
30 changes: 29 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 22 additions & 8 deletions src/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const BottomSheet = React.forwardRef<
// 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
const { ready, registerReady } = useReady()

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

Expand Down Expand Up @@ -438,12 +437,27 @@ export const BottomSheet = React.forwardRef<
}

let newY = down
? rubberbandIfOutOfBounds(
rawY,
onDismiss ? 0 : minSnapRef.current,
maxSnapRef.current,
0.55
)
? // @TODO figure out a better way to deal with rubberband overshooting if min and max have the same value
!onDismiss && minSnapRef.current === maxSnapRef.current
? rawY < minSnapRef.current
? rubberbandIfOutOfBounds(
rawY,
minSnapRef.current,
maxSnapRef.current * 2,
0.55
)
: rubberbandIfOutOfBounds(
rawY,
minSnapRef.current / 2,
maxSnapRef.current,
0.55
)
: rubberbandIfOutOfBounds(
rawY,
onDismiss ? 0 : minSnapRef.current,
maxSnapRef.current,
0.55
)
: predictedY

if (first) {
Expand Down Expand Up @@ -489,7 +503,7 @@ export const BottomSheet = React.forwardRef<
{...props}
data-rsbs-root
data-rsbs-is-blocking={blocking}
data-rsbs-is-dismissable={dismissable}
data-rsbs-is-dismissable={!!onDismiss}
data-rsbs-has-header={!!header}
data-rsbs-has-footer={!!footer}
className={className}
Expand Down

0 comments on commit 549ab30

Please sign in to comment.