Skip to content

Commit e2a2c9e

Browse files
committed
feat(modal): rename to snapBreakpoint
1 parent 8b033f6 commit e2a2c9e

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -429,28 +429,28 @@ export const createSheetGesture = (
429429
offset = clamp(0.0001, processedStep, maxStep);
430430
animation.progressStep(offset);
431431

432-
const predicted = calculatePredictedBreakpoint(detail.deltaY);
432+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY);
433433

434434
const eventDetail: ModalDragEventDetail = {
435435
currentY: detail.currentY,
436436
deltaY: detail.deltaY,
437437
velocityY: detail.velocityY,
438438
progress: calculateProgress(detail.currentY),
439-
predictedBreakpoint: predicted,
439+
snapBreakpoint: snapBreakpoint,
440440
};
441441

442442
onDragMove(eventDetail);
443443
};
444444

445445
const onEnd = (detail: GestureDetail) => {
446-
const predicted = calculatePredictedBreakpoint(detail.deltaY);
446+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY);
447447

448448
const eventDetail: ModalDragEventDetail = {
449449
currentY: detail.currentY,
450450
deltaY: detail.deltaY,
451451
velocityY: detail.velocityY,
452452
progress: calculateProgress(detail.currentY),
453-
predictedBreakpoint: predicted,
453+
snapBreakpoint,
454454
};
455455

456456
/**
@@ -473,7 +473,7 @@ export const createSheetGesture = (
473473
}
474474

475475
moveSheetToBreakpoint({
476-
breakpoint: predicted,
476+
breakpoint: snapBreakpoint,
477477
breakpointOffset: offset,
478478
canDismiss: canDismissBlocksGesture,
479479

@@ -644,31 +644,34 @@ export const createSheetGesture = (
644644
};
645645

646646
/**
647-
* Calculates the predicted breakpoint based on the current deltaY.
647+
* Calculates the breakpoint based on the current deltaY.
648648
* This determines where the sheet should snap to when the user releases the
649649
* gesture.
650650
*
651651
* @param deltaY The change in Y position since the gesture started.
652-
* @returns The predicted breakpoint value.
652+
* @returns The snap breakpoint value.
653653
*/
654-
const calculatePredictedBreakpoint = (deltaY: number): number => {
654+
const calculateSnapBreakpoint = (deltaY: number): number => {
655655
/**
656656
* Calculates the real-time vertical position of the modal.
657-
* We combine the wrapper's current bounding box position with the gesture's
658-
* deltaY to account for the physical movement during the drag.
657+
* We combine the wrapper's current bounding box position with the
658+
* gesture's deltaY to account for the physical movement during the drag.
659659
*/
660660
const currentY = wrapperEl.getBoundingClientRect().top + deltaY;
661+
/**
662+
* Convert that pixel position back into a 0 to 1 progress value.
663+
*/
661664
const currentProgress = calculateProgress(currentY);
662665

663666
/**
664-
* Find the breakpoint in the array that has the
665-
* smallest absolute distance to our current progress.
667+
* Find and return the defined breakpoint that is closest to the
668+
* current progress.
666669
*/
667-
const predicted = breakpoints.reduce((a, b) => {
670+
const snapBreakpoint = breakpoints.reduce((a, b) => {
668671
return Math.abs(b - currentProgress) < Math.abs(a - currentProgress) ? b : a;
669672
});
670673

671-
return predicted;
674+
return snapBreakpoint;
672675
};
673676

674677
/**

core/src/components/modal/modal-interface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ export interface ModalDragEventDetail {
5353
deltaY: number;
5454
velocityY: number;
5555
progress: number;
56-
predictedBreakpoint?: number;
56+
/**
57+
* The breakpoint that the sheet will snap to if the user releases
58+
* the gesture.
59+
*/
60+
snapBreakpoint?: number;
5761
}

core/src/components/modal/modal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class Modal implements ComponentInterface, OverlayInterface {
7272
private coreDelegate: FrameworkDelegate = CoreDelegate();
7373
private sheetTransition?: Promise<any>;
7474
@State() private isSheetModal = false;
75+
/**
76+
* The breakpoint value that has been committed for a sheet modal.
77+
* This represents the modal's resting state when it is not being dragged
78+
* or animating toward a new position.
79+
*/
7580
private currentBreakpoint?: number;
7681
private wrapperEl?: HTMLElement;
7782
private backdropEl?: HTMLIonBackdropElement;

0 commit comments

Comments
 (0)