@ionic/core 8.8.20-dev.11791394441.17aeb6fc → 8.8.20-dev.11791573097.1f843ab0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ion-modal.js +1 -1
- package/components/ion-select.js +1 -1
- package/components/p-DgVHyszQ.js +4 -0
- package/dist/cjs/ion-modal.cjs.entry.js +56 -85
- package/dist/collection/components/modal/gestures/sheet.js +58 -86
- package/dist/docs.json +1 -1
- package/dist/esm/ion-modal.entry.js +56 -85
- package/dist/ionic/ionic.esm.js +1 -1
- package/dist/ionic/p-ec4fa82d.entry.js +4 -0
- package/hydrate/index.js +56 -85
- package/hydrate/index.mjs +56 -85
- package/package.json +1 -1
- package/components/p-DBdldgo5.js +0 -4
- package/dist/ionic/p-dccdc1ff.entry.js +0 -4
|
@@ -1036,6 +1036,21 @@ const mdLeaveAnimation = (baseEl, opts) => {
|
|
|
1036
1036
|
return baseAnimation;
|
|
1037
1037
|
};
|
|
1038
1038
|
|
|
1039
|
+
/** Gesture velocity arrives in pixels per millisecond; the thresholds below are per second. */
|
|
1040
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
1041
|
+
/**
|
|
1042
|
+
* Flick speeds for the ionic theme's physics-based gesture, in pixels per
|
|
1043
|
+
* second. Both are magnitudes. Y grows downwards, so the upward threshold is
|
|
1044
|
+
* negated where it is compared.
|
|
1045
|
+
*/
|
|
1046
|
+
const FLICK_DOWN_VELOCITY = 500;
|
|
1047
|
+
/**
|
|
1048
|
+
* How far below its starting breakpoint a slow drag has to end to dismiss the
|
|
1049
|
+
* sheet. 0.4 means the user dragged 40% of the way down from where they started.
|
|
1050
|
+
*/
|
|
1051
|
+
const DISMISS_PROGRESS_RATIO = 0.4;
|
|
1052
|
+
/** How far ahead, in milliseconds, a drag's velocity is projected when snapping. */
|
|
1053
|
+
const FLICK_PROJECTION_MS = 350;
|
|
1039
1054
|
const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, backdropBreakpoint, animation, breakpoints = [], expandToScroll, getCurrentBreakpoint, onDismiss, onBreakpointChange, usePhysicsBasedGesture, onDragStart, onDragMove, onDragEnd) => {
|
|
1040
1055
|
var _a;
|
|
1041
1056
|
// Defaults for the sheet swipe animation
|
|
@@ -1062,6 +1077,11 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1062
1077
|
const contentEl = baseEl.querySelector('ion-content');
|
|
1063
1078
|
// Cache the initial value so the gesture restores it instead of forcing scrolling on.
|
|
1064
1079
|
const initialContentScrollY = (_a = contentEl === null || contentEl === void 0 ? void 0 : contentEl.scrollY) !== null && _a !== void 0 ? _a : true;
|
|
1080
|
+
/**
|
|
1081
|
+
* The height of the sheet the user actually sees. This comes from the wrapper
|
|
1082
|
+
* rather than the host element, which is stretched to the full viewport no
|
|
1083
|
+
* matter how tall the sheet itself is.
|
|
1084
|
+
*/
|
|
1065
1085
|
const height = wrapperEl.clientHeight;
|
|
1066
1086
|
let currentBreakpoint = initialBreakpoint;
|
|
1067
1087
|
let offset = 0;
|
|
@@ -1360,27 +1380,23 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1360
1380
|
: step;
|
|
1361
1381
|
offset = helpers.clamp(0.0001, processedStep, maxStep);
|
|
1362
1382
|
animation.progressStep(offset);
|
|
1363
|
-
const snapBreakpoint =
|
|
1364
|
-
? calculateVelocitySnapBreakpoint(detail.deltaY, detail.velocityY, detail.currentY)
|
|
1365
|
-
: calculatePositionSnapBreakpoint(detail.deltaY);
|
|
1383
|
+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY, detail.velocityY);
|
|
1366
1384
|
const eventDetail = {
|
|
1367
1385
|
currentY: detail.currentY,
|
|
1368
1386
|
deltaY: detail.deltaY,
|
|
1369
1387
|
velocityY: detail.velocityY,
|
|
1370
|
-
progress:
|
|
1388
|
+
progress: calculateEventProgress(detail.deltaY),
|
|
1371
1389
|
snapBreakpoint: snapBreakpoint,
|
|
1372
1390
|
};
|
|
1373
1391
|
onDragMove(eventDetail);
|
|
1374
1392
|
};
|
|
1375
1393
|
const onEnd = (detail) => {
|
|
1376
|
-
const snapBreakpoint =
|
|
1377
|
-
? calculateVelocitySnapBreakpoint(detail.deltaY, detail.velocityY, detail.currentY)
|
|
1378
|
-
: calculatePositionSnapBreakpoint(detail.deltaY);
|
|
1394
|
+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY, detail.velocityY);
|
|
1379
1395
|
const eventDetail = {
|
|
1380
1396
|
currentY: detail.currentY,
|
|
1381
1397
|
deltaY: detail.deltaY,
|
|
1382
1398
|
velocityY: detail.velocityY,
|
|
1383
|
-
progress:
|
|
1399
|
+
progress: calculateEventProgress(detail.deltaY),
|
|
1384
1400
|
snapBreakpoint,
|
|
1385
1401
|
};
|
|
1386
1402
|
/**
|
|
@@ -1568,6 +1584,20 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1568
1584
|
.progressEnd(1, 0, animated ? duration : 0);
|
|
1569
1585
|
});
|
|
1570
1586
|
};
|
|
1587
|
+
/**
|
|
1588
|
+
* Decides which breakpoint the sheet should settle on for the current drag.
|
|
1589
|
+
*
|
|
1590
|
+
* @param deltaY The change in Y position since the gesture started
|
|
1591
|
+
* @param velocityY The velocity in pixels per millisecond
|
|
1592
|
+
* @returns The snap breakpoint value
|
|
1593
|
+
*/
|
|
1594
|
+
const calculateSnapBreakpoint = (deltaY, velocityY) => {
|
|
1595
|
+
if (usePhysicsBasedGesture) {
|
|
1596
|
+
return calculateVelocitySnapBreakpoint(deltaY, velocityY);
|
|
1597
|
+
}
|
|
1598
|
+
// Project the drag forward so a quick flick counts.
|
|
1599
|
+
return calculatePositionSnapBreakpoint(deltaY + velocityY * FLICK_PROJECTION_MS);
|
|
1600
|
+
};
|
|
1571
1601
|
/**
|
|
1572
1602
|
* Calculates the breakpoint based on the current deltaY.
|
|
1573
1603
|
* This determines where the sheet should snap to when the user releases the
|
|
@@ -1577,16 +1607,7 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1577
1607
|
* @returns The snap breakpoint value.
|
|
1578
1608
|
*/
|
|
1579
1609
|
const calculatePositionSnapBreakpoint = (deltaY) => {
|
|
1580
|
-
|
|
1581
|
-
* Calculates the real-time vertical position of the modal.
|
|
1582
|
-
* We combine the wrapper's current bounding box position with the
|
|
1583
|
-
* gesture's deltaY to account for the physical movement during the drag.
|
|
1584
|
-
*/
|
|
1585
|
-
const currentY = wrapperEl.getBoundingClientRect().top + deltaY;
|
|
1586
|
-
/**
|
|
1587
|
-
* Convert that pixel position back into a 0 to 1 progress value.
|
|
1588
|
-
*/
|
|
1589
|
-
const currentProgress = calculateProgress(currentY);
|
|
1610
|
+
const currentProgress = calculateProgress(deltaY);
|
|
1590
1611
|
/**
|
|
1591
1612
|
* Find and return the defined breakpoint that is closest to the
|
|
1592
1613
|
* current progress.
|
|
@@ -1608,16 +1629,15 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1608
1629
|
*
|
|
1609
1630
|
* @param deltaY The change in Y position since gesture started
|
|
1610
1631
|
* @param velocityY The velocity in pixels per millisecond
|
|
1611
|
-
* @param currentY The current Y position of the gesture
|
|
1612
1632
|
* @returns The snap breakpoint value
|
|
1613
1633
|
*/
|
|
1614
|
-
const calculateVelocitySnapBreakpoint = (deltaY, velocityY
|
|
1634
|
+
const calculateVelocitySnapBreakpoint = (deltaY, velocityY) => {
|
|
1615
1635
|
// Convert velocity from px/ms to px/s for easier threshold comparison
|
|
1616
|
-
const velocityYPerSecond = velocityY *
|
|
1636
|
+
const velocityYPerSecond = velocityY * MILLISECONDS_PER_SECOND;
|
|
1617
1637
|
// Calculate current progress (0 = fully closed, 1 = fully expanded)
|
|
1618
|
-
const currentProgress = calculateProgress(
|
|
1638
|
+
const currentProgress = calculateProgress(deltaY);
|
|
1619
1639
|
// Rule 1: Fast downward flick always dismisses
|
|
1620
|
-
if (velocityYPerSecond >
|
|
1640
|
+
if (velocityYPerSecond > FLICK_DOWN_VELOCITY) {
|
|
1621
1641
|
return minBreakpoint;
|
|
1622
1642
|
}
|
|
1623
1643
|
// Rule 2: Fast upward flick moves to next breakpoint above
|
|
@@ -1632,8 +1652,7 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1632
1652
|
// Calculate how far we've moved below the current snap point
|
|
1633
1653
|
const distanceBelowSnap = currentBreakpoint - currentProgress;
|
|
1634
1654
|
const percentageBelowSnap = distanceBelowSnap / currentBreakpoint;
|
|
1635
|
-
|
|
1636
|
-
if (percentageBelowSnap > 0.4 && velocityYPerSecond <= 400) {
|
|
1655
|
+
if (percentageBelowSnap > DISMISS_PROGRESS_RATIO) {
|
|
1637
1656
|
return 0;
|
|
1638
1657
|
}
|
|
1639
1658
|
}
|
|
@@ -1641,74 +1660,26 @@ const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, ba
|
|
|
1641
1660
|
return calculatePositionSnapBreakpoint(deltaY);
|
|
1642
1661
|
};
|
|
1643
1662
|
/**
|
|
1644
|
-
* Calculates the
|
|
1645
|
-
*
|
|
1646
|
-
* The progress is a value between 0 and 1 that represents how far
|
|
1647
|
-
* the swipe has progressed towards closing the modal.
|
|
1663
|
+
* Calculates how open the sheet is part way through a gesture, on the same
|
|
1664
|
+
* 0 to 1 scale as the breakpoints: 1 is fully open and 0 is fully closed.
|
|
1648
1665
|
*
|
|
1649
|
-
*
|
|
1650
|
-
* while a value closer to 0 means the modal is closer to being closed.
|
|
1651
|
-
*
|
|
1652
|
-
* @param currentY The current Y position of the gesture
|
|
1666
|
+
* @param deltaY The change in Y position since the gesture started
|
|
1653
1667
|
* @returns The progress of the sheet gesture
|
|
1654
1668
|
*/
|
|
1655
|
-
const calculateProgress = (
|
|
1656
|
-
|
|
1657
|
-
const
|
|
1658
|
-
/**
|
|
1659
|
-
* The lowest point the sheet can be dragged to aka the point at which
|
|
1660
|
-
* the sheet is fully closed.
|
|
1661
|
-
*/
|
|
1662
|
-
const maxY = convertBreakpointToY(minBreakpoint);
|
|
1663
|
-
/**
|
|
1664
|
-
* The highest point the sheet can be dragged to aka the point at which
|
|
1665
|
-
* the sheet is fully open.
|
|
1666
|
-
*/
|
|
1667
|
-
const minY = convertBreakpointToY(maxBreakpoint);
|
|
1668
|
-
// The total distance between the fully open and fully closed positions.
|
|
1669
|
-
const totalDistance = maxY - minY;
|
|
1670
|
-
// The distance from the current position to the fully closed position.
|
|
1671
|
-
const distanceFromBottom = maxY - currentY;
|
|
1672
|
-
/**
|
|
1673
|
-
* The progress represents how far the sheet is from the bottom relative
|
|
1674
|
-
* to the total distance. When the user starts swiping up, the progress
|
|
1675
|
-
* should be close to 1, and when the user has swiped all the way down,
|
|
1676
|
-
* the progress should be close to 0.
|
|
1677
|
-
*/
|
|
1678
|
-
const progress = distanceFromBottom / totalDistance;
|
|
1669
|
+
const calculateProgress = (deltaY) => {
|
|
1670
|
+
// Mirrors the animation step in onMove, so the snap matches where the sheet is drawn.
|
|
1671
|
+
const progress = currentBreakpoint - deltaY / height;
|
|
1679
1672
|
// Round to the nearest thousandth to avoid returning very small decimal
|
|
1680
1673
|
const roundedProgress = Math.round(progress * 1000) / 1000;
|
|
1681
|
-
return
|
|
1674
|
+
return helpers.clamp(0, roundedProgress, 1);
|
|
1682
1675
|
};
|
|
1683
1676
|
/**
|
|
1684
|
-
*
|
|
1685
|
-
*
|
|
1686
|
-
*
|
|
1687
|
-
* @param breakpoint The breakpoint value (e.g., 0.5 for half-open)
|
|
1688
|
-
* @returns The pixel Y coordinate on the screen
|
|
1677
|
+
* Scales the progress from the lowest to the highest breakpoint, so the
|
|
1678
|
+
* drag events report 0 at the lowest breakpoint and 1 at the highest.
|
|
1689
1679
|
*/
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
|
|
1693
|
-
// The bottom of the screen.
|
|
1694
|
-
const viewportBottom = window.innerHeight;
|
|
1695
|
-
/**
|
|
1696
|
-
* The active height is how much of the modal is actually showing
|
|
1697
|
-
* on the screen for this specific breakpoint.
|
|
1698
|
-
*/
|
|
1699
|
-
const activeHeight = modalHeight * breakpoint;
|
|
1700
|
-
/**
|
|
1701
|
-
* To find the Y coordinate, start at the bottom of the screen
|
|
1702
|
-
* and move up by the active height of the modal.
|
|
1703
|
-
*
|
|
1704
|
-
* A breakpoint of 1.0 means the active height is the full modal height
|
|
1705
|
-
* (fully open). A breakpoint of 0.0 means the active height is 0
|
|
1706
|
-
* (fully closed).
|
|
1707
|
-
*
|
|
1708
|
-
* Since screen Y coordinates get smaller as you go up, we subtract the
|
|
1709
|
-
* active height from the viewport bottom.
|
|
1710
|
-
*/
|
|
1711
|
-
return viewportBottom - activeHeight;
|
|
1680
|
+
const calculateEventProgress = (deltaY) => {
|
|
1681
|
+
const progress = (calculateProgress(deltaY) - minBreakpoint) / (maxBreakpoint - minBreakpoint);
|
|
1682
|
+
return helpers.clamp(0, progress, 1);
|
|
1712
1683
|
};
|
|
1713
1684
|
const gesture = index$1.createGesture({
|
|
1714
1685
|
el: wrapperEl,
|
|
@@ -7,6 +7,22 @@ import { clamp, getElementRoot, raf } from "../../../utils/helpers";
|
|
|
7
7
|
import { FOCUS_TRAP_DISABLE_CLASS } from "../../../utils/overlays";
|
|
8
8
|
import { getBackdropValueForSheet } from "../utils";
|
|
9
9
|
import { calculateSpringStep, canSwipeOnContent, handleCanDismiss } from "./utils";
|
|
10
|
+
/** Gesture velocity arrives in pixels per millisecond; the thresholds below are per second. */
|
|
11
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
12
|
+
/**
|
|
13
|
+
* Flick speeds for the ionic theme's physics-based gesture, in pixels per
|
|
14
|
+
* second. Both are magnitudes. Y grows downwards, so the upward threshold is
|
|
15
|
+
* negated where it is compared.
|
|
16
|
+
*/
|
|
17
|
+
const FLICK_DOWN_VELOCITY = 500;
|
|
18
|
+
const FLICK_UP_VELOCITY = 400;
|
|
19
|
+
/**
|
|
20
|
+
* How far below its starting breakpoint a slow drag has to end to dismiss the
|
|
21
|
+
* sheet. 0.4 means the user dragged 40% of the way down from where they started.
|
|
22
|
+
*/
|
|
23
|
+
const DISMISS_PROGRESS_RATIO = 0.4;
|
|
24
|
+
/** How far ahead, in milliseconds, a drag's velocity is projected when snapping. */
|
|
25
|
+
const FLICK_PROJECTION_MS = 350;
|
|
10
26
|
export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpoint, backdropBreakpoint, animation, breakpoints = [], expandToScroll, getCurrentBreakpoint, onDismiss, onBreakpointChange, usePhysicsBasedGesture, onDragStart, onDragMove, onDragEnd) => {
|
|
11
27
|
var _a;
|
|
12
28
|
// Defaults for the sheet swipe animation
|
|
@@ -33,6 +49,11 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
33
49
|
const contentEl = baseEl.querySelector('ion-content');
|
|
34
50
|
// Cache the initial value so the gesture restores it instead of forcing scrolling on.
|
|
35
51
|
const initialContentScrollY = (_a = contentEl === null || contentEl === void 0 ? void 0 : contentEl.scrollY) !== null && _a !== void 0 ? _a : true;
|
|
52
|
+
/**
|
|
53
|
+
* The height of the sheet the user actually sees. This comes from the wrapper
|
|
54
|
+
* rather than the host element, which is stretched to the full viewport no
|
|
55
|
+
* matter how tall the sheet itself is.
|
|
56
|
+
*/
|
|
36
57
|
const height = wrapperEl.clientHeight;
|
|
37
58
|
let currentBreakpoint = initialBreakpoint;
|
|
38
59
|
let offset = 0;
|
|
@@ -331,27 +352,23 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
331
352
|
: step;
|
|
332
353
|
offset = clamp(0.0001, processedStep, maxStep);
|
|
333
354
|
animation.progressStep(offset);
|
|
334
|
-
const snapBreakpoint =
|
|
335
|
-
? calculateVelocitySnapBreakpoint(detail.deltaY, detail.velocityY, detail.currentY)
|
|
336
|
-
: calculatePositionSnapBreakpoint(detail.deltaY);
|
|
355
|
+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY, detail.velocityY);
|
|
337
356
|
const eventDetail = {
|
|
338
357
|
currentY: detail.currentY,
|
|
339
358
|
deltaY: detail.deltaY,
|
|
340
359
|
velocityY: detail.velocityY,
|
|
341
|
-
progress:
|
|
360
|
+
progress: calculateEventProgress(detail.deltaY),
|
|
342
361
|
snapBreakpoint: snapBreakpoint,
|
|
343
362
|
};
|
|
344
363
|
onDragMove(eventDetail);
|
|
345
364
|
};
|
|
346
365
|
const onEnd = (detail) => {
|
|
347
|
-
const snapBreakpoint =
|
|
348
|
-
? calculateVelocitySnapBreakpoint(detail.deltaY, detail.velocityY, detail.currentY)
|
|
349
|
-
: calculatePositionSnapBreakpoint(detail.deltaY);
|
|
366
|
+
const snapBreakpoint = calculateSnapBreakpoint(detail.deltaY, detail.velocityY);
|
|
350
367
|
const eventDetail = {
|
|
351
368
|
currentY: detail.currentY,
|
|
352
369
|
deltaY: detail.deltaY,
|
|
353
370
|
velocityY: detail.velocityY,
|
|
354
|
-
progress:
|
|
371
|
+
progress: calculateEventProgress(detail.deltaY),
|
|
355
372
|
snapBreakpoint,
|
|
356
373
|
};
|
|
357
374
|
/**
|
|
@@ -539,6 +556,20 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
539
556
|
.progressEnd(1, 0, animated ? duration : 0);
|
|
540
557
|
});
|
|
541
558
|
};
|
|
559
|
+
/**
|
|
560
|
+
* Decides which breakpoint the sheet should settle on for the current drag.
|
|
561
|
+
*
|
|
562
|
+
* @param deltaY The change in Y position since the gesture started
|
|
563
|
+
* @param velocityY The velocity in pixels per millisecond
|
|
564
|
+
* @returns The snap breakpoint value
|
|
565
|
+
*/
|
|
566
|
+
const calculateSnapBreakpoint = (deltaY, velocityY) => {
|
|
567
|
+
if (usePhysicsBasedGesture) {
|
|
568
|
+
return calculateVelocitySnapBreakpoint(deltaY, velocityY);
|
|
569
|
+
}
|
|
570
|
+
// Project the drag forward so a quick flick counts.
|
|
571
|
+
return calculatePositionSnapBreakpoint(deltaY + velocityY * FLICK_PROJECTION_MS);
|
|
572
|
+
};
|
|
542
573
|
/**
|
|
543
574
|
* Calculates the breakpoint based on the current deltaY.
|
|
544
575
|
* This determines where the sheet should snap to when the user releases the
|
|
@@ -548,16 +579,7 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
548
579
|
* @returns The snap breakpoint value.
|
|
549
580
|
*/
|
|
550
581
|
const calculatePositionSnapBreakpoint = (deltaY) => {
|
|
551
|
-
|
|
552
|
-
* Calculates the real-time vertical position of the modal.
|
|
553
|
-
* We combine the wrapper's current bounding box position with the
|
|
554
|
-
* gesture's deltaY to account for the physical movement during the drag.
|
|
555
|
-
*/
|
|
556
|
-
const currentY = wrapperEl.getBoundingClientRect().top + deltaY;
|
|
557
|
-
/**
|
|
558
|
-
* Convert that pixel position back into a 0 to 1 progress value.
|
|
559
|
-
*/
|
|
560
|
-
const currentProgress = calculateProgress(currentY);
|
|
582
|
+
const currentProgress = calculateProgress(deltaY);
|
|
561
583
|
/**
|
|
562
584
|
* Find and return the defined breakpoint that is closest to the
|
|
563
585
|
* current progress.
|
|
@@ -579,20 +601,19 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
579
601
|
*
|
|
580
602
|
* @param deltaY The change in Y position since gesture started
|
|
581
603
|
* @param velocityY The velocity in pixels per millisecond
|
|
582
|
-
* @param currentY The current Y position of the gesture
|
|
583
604
|
* @returns The snap breakpoint value
|
|
584
605
|
*/
|
|
585
|
-
const calculateVelocitySnapBreakpoint = (deltaY, velocityY
|
|
606
|
+
const calculateVelocitySnapBreakpoint = (deltaY, velocityY) => {
|
|
586
607
|
// Convert velocity from px/ms to px/s for easier threshold comparison
|
|
587
|
-
const velocityYPerSecond = velocityY *
|
|
608
|
+
const velocityYPerSecond = velocityY * MILLISECONDS_PER_SECOND;
|
|
588
609
|
// Calculate current progress (0 = fully closed, 1 = fully expanded)
|
|
589
|
-
const currentProgress = calculateProgress(
|
|
610
|
+
const currentProgress = calculateProgress(deltaY);
|
|
590
611
|
// Rule 1: Fast downward flick always dismisses
|
|
591
|
-
if (velocityYPerSecond >
|
|
612
|
+
if (velocityYPerSecond > FLICK_DOWN_VELOCITY) {
|
|
592
613
|
return minBreakpoint;
|
|
593
614
|
}
|
|
594
615
|
// Rule 2: Fast upward flick moves to next breakpoint above
|
|
595
|
-
if (velocityYPerSecond < -
|
|
616
|
+
if (velocityYPerSecond < -FLICK_UP_VELOCITY) {
|
|
596
617
|
// Find next breakpoint above current position
|
|
597
618
|
const nextBreakpoint = breakpoints.find((bp) => bp > currentProgress);
|
|
598
619
|
// If no breakpoint above, stay at max breakpoint
|
|
@@ -603,8 +624,7 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
603
624
|
// Calculate how far we've moved below the current snap point
|
|
604
625
|
const distanceBelowSnap = currentBreakpoint - currentProgress;
|
|
605
626
|
const percentageBelowSnap = distanceBelowSnap / currentBreakpoint;
|
|
606
|
-
|
|
607
|
-
if (percentageBelowSnap > 0.4 && velocityYPerSecond <= 400) {
|
|
627
|
+
if (percentageBelowSnap > DISMISS_PROGRESS_RATIO) {
|
|
608
628
|
return 0;
|
|
609
629
|
}
|
|
610
630
|
}
|
|
@@ -612,74 +632,26 @@ export const createSheetGesture = (baseEl, backdropEl, wrapperEl, initialBreakpo
|
|
|
612
632
|
return calculatePositionSnapBreakpoint(deltaY);
|
|
613
633
|
};
|
|
614
634
|
/**
|
|
615
|
-
* Calculates the
|
|
635
|
+
* Calculates how open the sheet is part way through a gesture, on the same
|
|
636
|
+
* 0 to 1 scale as the breakpoints: 1 is fully open and 0 is fully closed.
|
|
616
637
|
*
|
|
617
|
-
*
|
|
618
|
-
* the swipe has progressed towards closing the modal.
|
|
619
|
-
*
|
|
620
|
-
* A value closer to 1 means the modal is closer to being opened,
|
|
621
|
-
* while a value closer to 0 means the modal is closer to being closed.
|
|
622
|
-
*
|
|
623
|
-
* @param currentY The current Y position of the gesture
|
|
638
|
+
* @param deltaY The change in Y position since the gesture started
|
|
624
639
|
* @returns The progress of the sheet gesture
|
|
625
640
|
*/
|
|
626
|
-
const calculateProgress = (
|
|
627
|
-
|
|
628
|
-
const
|
|
629
|
-
/**
|
|
630
|
-
* The lowest point the sheet can be dragged to aka the point at which
|
|
631
|
-
* the sheet is fully closed.
|
|
632
|
-
*/
|
|
633
|
-
const maxY = convertBreakpointToY(minBreakpoint);
|
|
634
|
-
/**
|
|
635
|
-
* The highest point the sheet can be dragged to aka the point at which
|
|
636
|
-
* the sheet is fully open.
|
|
637
|
-
*/
|
|
638
|
-
const minY = convertBreakpointToY(maxBreakpoint);
|
|
639
|
-
// The total distance between the fully open and fully closed positions.
|
|
640
|
-
const totalDistance = maxY - minY;
|
|
641
|
-
// The distance from the current position to the fully closed position.
|
|
642
|
-
const distanceFromBottom = maxY - currentY;
|
|
643
|
-
/**
|
|
644
|
-
* The progress represents how far the sheet is from the bottom relative
|
|
645
|
-
* to the total distance. When the user starts swiping up, the progress
|
|
646
|
-
* should be close to 1, and when the user has swiped all the way down,
|
|
647
|
-
* the progress should be close to 0.
|
|
648
|
-
*/
|
|
649
|
-
const progress = distanceFromBottom / totalDistance;
|
|
641
|
+
const calculateProgress = (deltaY) => {
|
|
642
|
+
// Mirrors the animation step in onMove, so the snap matches where the sheet is drawn.
|
|
643
|
+
const progress = currentBreakpoint - deltaY / height;
|
|
650
644
|
// Round to the nearest thousandth to avoid returning very small decimal
|
|
651
645
|
const roundedProgress = Math.round(progress * 1000) / 1000;
|
|
652
|
-
return
|
|
646
|
+
return clamp(0, roundedProgress, 1);
|
|
653
647
|
};
|
|
654
648
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* @param breakpoint The breakpoint value (e.g., 0.5 for half-open)
|
|
659
|
-
* @returns The pixel Y coordinate on the screen
|
|
649
|
+
* Scales the progress from the lowest to the highest breakpoint, so the
|
|
650
|
+
* drag events report 0 at the lowest breakpoint and 1 at the highest.
|
|
660
651
|
*/
|
|
661
|
-
const
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
// The bottom of the screen.
|
|
665
|
-
const viewportBottom = window.innerHeight;
|
|
666
|
-
/**
|
|
667
|
-
* The active height is how much of the modal is actually showing
|
|
668
|
-
* on the screen for this specific breakpoint.
|
|
669
|
-
*/
|
|
670
|
-
const activeHeight = modalHeight * breakpoint;
|
|
671
|
-
/**
|
|
672
|
-
* To find the Y coordinate, start at the bottom of the screen
|
|
673
|
-
* and move up by the active height of the modal.
|
|
674
|
-
*
|
|
675
|
-
* A breakpoint of 1.0 means the active height is the full modal height
|
|
676
|
-
* (fully open). A breakpoint of 0.0 means the active height is 0
|
|
677
|
-
* (fully closed).
|
|
678
|
-
*
|
|
679
|
-
* Since screen Y coordinates get smaller as you go up, we subtract the
|
|
680
|
-
* active height from the viewport bottom.
|
|
681
|
-
*/
|
|
682
|
-
return viewportBottom - activeHeight;
|
|
652
|
+
const calculateEventProgress = (deltaY) => {
|
|
653
|
+
const progress = (calculateProgress(deltaY) - minBreakpoint) / (maxBreakpoint - minBreakpoint);
|
|
654
|
+
return clamp(0, progress, 1);
|
|
683
655
|
};
|
|
684
656
|
const gesture = createGesture({
|
|
685
657
|
el: wrapperEl,
|
package/dist/docs.json
CHANGED