Skip to content

Commit 6782ced

Browse files
committed
Add optional bounce
1 parent 62f6f50 commit 6782ced

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/sheet.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ export const Sheet = forwardRef<any, SheetProps>(
216216

217217
const onDragStart = useStableCallback<DragHandler>((event, info) => {
218218
yUnconstrainedRef.current = y.get();
219+
if (y.isAnimating()) {
220+
y.stop();
221+
}
219222
onDragStartProp?.(event, info);
220223
if (event.defaultPrevented) return;
221224
blurActiveInput();
@@ -229,6 +232,7 @@ export const Sheet = forwardRef<any, SheetProps>(
229232
const currentY = y.get();
230233

231234
let yTo = 0;
235+
let snapIndex: number | undefined;
232236

233237
const currentSnapPoint =
234238
currentSnap !== undefined ? getSnapPoint(currentSnap) : null;
@@ -257,6 +261,7 @@ export const Sheet = forwardRef<any, SheetProps>(
257261
}
258262

259263
yTo = result.yTo;
264+
snapIndex = result.snapIndex;
260265

261266
// If disableDismiss is true, prevent closing via gesture
262267
if (disableDismiss && yTo + 1 >= sheetHeight) {
@@ -265,6 +270,7 @@ export const Sheet = forwardRef<any, SheetProps>(
265270

266271
if (bottomSnapPoint) {
267272
yTo = bottomSnapPoint.snapValueY;
273+
snapIndex = bottomSnapPoint.snapIndex;
268274
updateSnap(bottomSnapPoint.snapIndex);
269275
} else {
270276
// If no open snap points available, stay at current position
@@ -287,8 +293,10 @@ export const Sheet = forwardRef<any, SheetProps>(
287293
}
288294
}
289295

296+
const shouldBounce = currentSnapPoint?.snapIndex !== snapIndex;
297+
290298
// Update the spring value so that the sheet is animated to the snap point
291-
animate(y, yTo, animationOptions);
299+
animate(y, yTo, { ...animationOptions, bounce: shouldBounce ? 0.2 : 0 });
292300
yUnconstrainedRef.current = undefined;
293301

294302
// +1px for imprecision tolerance

0 commit comments

Comments
 (0)