Skip to content

Commit 2c9dfa1

Browse files
committed
refactor: moved exit condition to the top of the onEnd function
1 parent ff99204 commit 2c9dfa1

File tree

1 file changed

+12
-12
lines changed
  • core/src/components/modal/gestures

1 file changed

+12
-12
lines changed

core/src/components/modal/gestures/sheet.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,6 @@ export const createSheetGesture = (
328328
};
329329

330330
const onEnd = (detail: GestureDetail) => {
331-
/**
332-
* When the gesture releases, we need to determine
333-
* the closest breakpoint to snap to.
334-
*/
335-
const velocity = detail.velocityY;
336-
const threshold = (detail.deltaY + velocity * 350) / height;
337-
338-
const diff = currentBreakpoint - threshold;
339-
const closest = breakpoints.reduce((a, b) => {
340-
return Math.abs(b - diff) < Math.abs(a - diff) ? b : a;
341-
});
342-
343331
/**
344332
* If expandToScroll is disabled, we should not allow the moveSheetToBreakpoint
345333
* function to be called if the user is trying to swipe upwards and the content
@@ -353,6 +341,18 @@ export const createSheetGesture = (
353341
}
354342
}
355343

344+
/**
345+
* When the gesture releases, we need to determine
346+
* the closest breakpoint to snap to.
347+
*/
348+
const velocity = detail.velocityY;
349+
const threshold = (detail.deltaY + velocity * 350) / height;
350+
351+
const diff = currentBreakpoint - threshold;
352+
const closest = breakpoints.reduce((a, b) => {
353+
return Math.abs(b - diff) < Math.abs(a - diff) ? b : a;
354+
});
355+
356356
moveSheetToBreakpoint({
357357
breakpoint: closest,
358358
breakpointOffset: offset,

0 commit comments

Comments
 (0)