@astryxdesign/core 0.7.9-canary.e9bfd12 → 0.7.9-canary.ef3db95
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/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +40 -8
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +61 -21
- package/dist/astryx.css +4 -4
- package/package.json +4 -4
- package/src/BottomSheet/BottomSheetPanel.tsx +64 -7
- package/src/BottomSheet/useSheetGestures.ts +83 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetPanel.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheetPanel.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"BottomSheetPanel.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheetPanel.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAgC5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAQvB,QAAA,MAAM,cAAc;;;;CAIV,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,cAAc,CAAC;AAC5D,YAAY,EAAC,oBAAoB,EAAC,CAAC;AAgFnC,eAAO,MAAM,2BAA2B,2DACkB,CAAC;AA+N3D,MAAM,MAAM,sBAAsB,GAChC,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAC7B;IAAC,IAAI,EAAE,QAAQ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CAAC;CAC7D;AAyJD,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,KAAK,EACL,eAAe,EACf,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,SAAS,EACT,KAAK,EACL,QAAQ,EACR,MAAM,EACN,cAAsB,EACtB,cAAc,EACd,eAAe,EACf,qBAA4B,EAC5B,kBAA0B,EAC1B,SAAS,EACT,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,GAAG,KAAK,EACT,EAAE,qBAAqB,+BA0bvB;yBAlde,gBAAgB"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* - /packages/core/src/BottomSheet/useSheetGestures.ts
|
|
19
19
|
* - /packages/core/src/Layout/container.stylex.ts (bottom-sheet padding chain)
|
|
20
20
|
*/
|
|
21
|
-
import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef } from 'react';
|
|
21
|
+
import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
22
22
|
import * as stylex from '@stylexjs/stylex';
|
|
23
23
|
import { useDevWarning } from "../hooks/useDevWarning.js";
|
|
24
24
|
import { useMediaQuery } from "../hooks/useMediaQuery.js";
|
|
@@ -33,6 +33,7 @@ import { layerStructureReset } from "../Layer/layerStructureReset.stylex.js";
|
|
|
33
33
|
import { LayerContentBoundary } from "../Layer/layerScopedContext.js";
|
|
34
34
|
import { container } from "../Layout/container.stylex.js";
|
|
35
35
|
import { containerPaddingBlockEndVarStyles, containerPaddingBlockStartVarStyles, containerPaddingInlineVarStyles, overlayPaddingReset, paddingStyles, spacingStepToToken } from "../Layout/padding.stylex.js";
|
|
36
|
+
import { subscribeInput } from "../utils/inputStream.js";
|
|
36
37
|
import { isValidSnapPoint, resolveSnapPoints } from "./snapOffsets.js";
|
|
37
38
|
import { useMobileKeyboard } from "../keyboard/useMobileKeyboard.js";
|
|
38
39
|
import { scrollPreservationPadding, sheetLayoutHeight, useSheetGestures } from "./useSheetGestures.js";
|
|
@@ -42,8 +43,16 @@ const HEIGHT_BUDGETS = {
|
|
|
42
43
|
capped: '62dvh',
|
|
43
44
|
tall: '92dvh'
|
|
44
45
|
};
|
|
45
|
-
//
|
|
46
|
-
|
|
46
|
+
// The reserve: how far the sheet's surface reaches below the screen, so a
|
|
47
|
+
// pull past the top never shows the page under it.
|
|
48
|
+
// SYNC: OVERSCROLL_MAX in useSheetGestures.ts must not exceed MIN_RESERVE.
|
|
49
|
+
const MIN_RESERVE = 48;
|
|
50
|
+
// A finger can pull past the top by at most the viewport's height. The rubber
|
|
51
|
+
// band over a sheet as tall as the viewport then shows 35.5% of it.
|
|
52
|
+
const RESERVE_VIEWPORT_SHARE = 0.4;
|
|
53
|
+
function sheetReserve(viewportHeight) {
|
|
54
|
+
return Math.max(MIN_RESERVE, Math.ceil(viewportHeight * RESERVE_VIEWPORT_SHARE));
|
|
55
|
+
}
|
|
47
56
|
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
|
|
48
57
|
const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
49
58
|
// The floating handle bar's height. The bar is out of flow, so this is not
|
|
@@ -51,6 +60,12 @@ const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
|
51
60
|
// from the sheet's top edge, inside the space a content wrapper's own top
|
|
52
61
|
// padding already provides.
|
|
53
62
|
const HANDLE_BAR_HEIGHT = spacingVars['--spacing-6'];
|
|
63
|
+
const BLOCK_SIZE_PROPERTIES = ['height', 'minHeight', 'maxHeight', 'blockSize', 'minBlockSize', 'maxBlockSize'];
|
|
64
|
+
|
|
65
|
+
/** Whether StyleX styles hold any style: they can nest in arrays. */
|
|
66
|
+
function hasStyles(xstyle) {
|
|
67
|
+
return Array.isArray(xstyle) ? xstyle.some(hasStyles) : xstyle != null && typeof xstyle === 'object';
|
|
68
|
+
}
|
|
54
69
|
|
|
55
70
|
// Measure the viewport that the height budgets use. They are `dvh`, which
|
|
56
71
|
// the virtual keyboard does not shrink, so `visualViewport` would differ by
|
|
@@ -59,6 +74,12 @@ const HANDLE_BAR_HEIGHT = spacingVars['--spacing-6'];
|
|
|
59
74
|
function layoutViewportHeight() {
|
|
60
75
|
return typeof window === 'undefined' ? 0 : window.innerHeight;
|
|
61
76
|
}
|
|
77
|
+
function subscribeToResize(onChange) {
|
|
78
|
+
return subscribeInput(window, 'resize', onChange);
|
|
79
|
+
}
|
|
80
|
+
function subscribeToNothing() {
|
|
81
|
+
return () => {};
|
|
82
|
+
}
|
|
62
83
|
|
|
63
84
|
/**
|
|
64
85
|
* A stable identity for a set of snap points. Type-tagged, so the fraction
|
|
@@ -112,8 +133,8 @@ const styles = {
|
|
|
112
133
|
kGVxlE: "x1kcpxr7",
|
|
113
134
|
kI3sdo: "x1a2a7pz",
|
|
114
135
|
kVQacm: "xb3r6kr",
|
|
115
|
-
kGO01o: "
|
|
116
|
-
k1K539: "
|
|
136
|
+
kGO01o: "x5559hn",
|
|
137
|
+
k1K539: "xgwt18o",
|
|
117
138
|
k3aq6I: "xnn1q72 xhbqy3z xspp5ug",
|
|
118
139
|
kSiTet: "x1hc1fzr x1igigxu xgo67oj",
|
|
119
140
|
k1ekBW: "xwcsmn1",
|
|
@@ -178,12 +199,12 @@ const styles = {
|
|
|
178
199
|
"--x-nsbhg8": (val => typeof val === "number" ? val + "px" : val != null ? val : undefined)(inset)
|
|
179
200
|
}],
|
|
180
201
|
budget: {
|
|
181
|
-
kZKoxP: "
|
|
202
|
+
kZKoxP: "x1fqcpoh",
|
|
182
203
|
$$css: true
|
|
183
204
|
},
|
|
184
205
|
hugHeight: {
|
|
185
206
|
kZKoxP: "xg7h5cd",
|
|
186
|
-
kskxy: "
|
|
207
|
+
kskxy: "xkche18",
|
|
187
208
|
$$css: true
|
|
188
209
|
}
|
|
189
210
|
};
|
|
@@ -390,6 +411,16 @@ export function BottomSheetPanel({
|
|
|
390
411
|
|
|
391
412
|
// A caller's height owns the element's height: the drag never writes it.
|
|
392
413
|
const consumerHeight = style?.height;
|
|
414
|
+
// StyleX styles and a class name can size the sheet too. Their rules are
|
|
415
|
+
// only class names here, so any of them counts as a size.
|
|
416
|
+
const isSizedByCaller = BLOCK_SIZE_PROPERTIES.some(property => style?.[property] != null) || hasStyles(xstyle) || className != null && className !== '';
|
|
417
|
+
// Only a finger stretches the sheet past MIN_RESERVE, so a device with no
|
|
418
|
+
// touch pointer keeps the smallest reserve. So does a sheet the caller
|
|
419
|
+
// sizes, which nothing extends by the reserve; the stretch stops at it.
|
|
420
|
+
const hasTouchPointer = useMediaQuery('(any-pointer: coarse)');
|
|
421
|
+
const tracksViewport = isPresented && hasTouchPointer && !isSizedByCaller;
|
|
422
|
+
const viewportHeight = useSyncExternalStore(tracksViewport ? subscribeToResize : subscribeToNothing, () => tracksViewport ? layoutViewportHeight() : 0, () => 0);
|
|
423
|
+
const reserve = viewportHeight > 0 ? sheetReserve(viewportHeight) : MIN_RESERVE;
|
|
393
424
|
const {
|
|
394
425
|
contentProps,
|
|
395
426
|
handleProps,
|
|
@@ -409,7 +440,7 @@ export function BottomSheetPanel({
|
|
|
409
440
|
isOpen: isInteractive,
|
|
410
441
|
isOpenRequested: isOpenRequested ?? isInteractive,
|
|
411
442
|
canDismiss: isSwipeDismissAllowed,
|
|
412
|
-
offscreenBlockEndInset:
|
|
443
|
+
offscreenBlockEndInset: reserve,
|
|
413
444
|
onDismiss,
|
|
414
445
|
snapHeights,
|
|
415
446
|
onTravelStart: () => {
|
|
@@ -624,6 +655,7 @@ export function BottomSheetPanel({
|
|
|
624
655
|
},
|
|
625
656
|
...mergeProps(themeProps('bottom-sheet'), stylex.props(layerTextReset.reset, layerStructureReset.reset, styles.sheet, overlayPaddingReset.reset, height === 'hug' ? styles.hugHeight : styles.budget, isClosing && styles.sheetClosing, isClosing && isCrossFade && styles.sheetClosingCrossFade, isFading && styles.sheetFading, isInactive && styles.sheetInactive, isEntrySettled && styles.sheetSettled, xstyle), className, {
|
|
626
657
|
['--_sheet-budget']: budget,
|
|
658
|
+
['--_sheet-reserve']: `${reserve}px`,
|
|
627
659
|
...(isInteractive ? gestureStyle : isRetained || isClosing ? {
|
|
628
660
|
height: hostHeight
|
|
629
661
|
} : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSheetGestures.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/useSheetGestures.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAoCH,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,YAAY,IAAI,iBAAiB,EACtC,KAAK,SAAS,EACd,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,OAAO,IAAI,YAAY,EAC7B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useSheetGestures.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/useSheetGestures.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAoCH,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,YAAY,IAAI,iBAAiB,EACtC,KAAK,SAAS,EACd,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,OAAO,IAAI,YAAY,EAC7B,MAAM,OAAO,CAAC;AA4Hf;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3E;AA+BD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,GAAG,IAAI,EAC1B,IAAI,EAAE,WAAW,GAChB,OAAO,CAWT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,GAAG,IAAI,EAC1B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AAC,MAAM,CAAC,CAAC;IACnC,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,uBAAuB,EAAE,MAAM,CAAC;IAChC,qEAAqE;IACrE,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;;;;OAOG;IACH,wBAAwB,EAAE,MAAM,IAAI,CAAC;IACrC;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AASD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,eAAwB,EACxB,UAAiB,EACjB,sBAA0B,EAC1B,SAAS,EACT,WAAW,EACX,MAAM,EACN,aAAa,EACb,cAAc,EACd,cAAsB,GACvB,EAAE,uBAAuB,GAAG,sBAAsB,CAg3ClD"}
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
// finger ends any drag (yieldToPinch). There is no module-scope DOM access,
|
|
50
50
|
// so the hook is SSR-safe. Reduced motion skips the settle transition.
|
|
51
51
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
52
|
+
import { rubberBand } from "../motion/rubberBand.js";
|
|
53
|
+
import { scroll } from "../motion/uikit/scroll.js";
|
|
52
54
|
import { computeDetentOffsets, peekOffsetFor, resolveSettleOffset, scrimOpacityForOffset } from "./snapOffsets.js";
|
|
53
55
|
|
|
54
56
|
/**
|
|
@@ -86,13 +88,17 @@ const MAGNET_RANGE = 40;
|
|
|
86
88
|
function isSyntheticTouch(event) {
|
|
87
89
|
return event.syntheticTouch === true;
|
|
88
90
|
}
|
|
91
|
+
// An Apple Pencil raises touch events too, marked `stylus`. Its drag is a
|
|
92
|
+
// pen's, as on the grabber, where WebKit reports it as a pen.
|
|
93
|
+
function touchPointerType(touch) {
|
|
94
|
+
return touch.touchType === 'stylus' ? 'pen' : 'touch';
|
|
95
|
+
}
|
|
89
96
|
|
|
90
|
-
//
|
|
91
|
-
//
|
|
97
|
+
// A mouse's stretch past fully open: a resisted fraction of the drag, capped
|
|
98
|
+
// at OVERSCROLL_MAX.
|
|
92
99
|
const OVERSCROLL_RESISTANCE = 0.35;
|
|
93
|
-
// SYNC: must
|
|
94
|
-
//
|
|
95
|
-
// import so it can be used inside stylex.create there.
|
|
100
|
+
// SYNC: must not exceed MIN_RESERVE in BottomSheetPanel.tsx, the smallest
|
|
101
|
+
// reserve the sheet keeps below the screen.
|
|
96
102
|
const OVERSCROLL_MAX = 48;
|
|
97
103
|
// Travel past the point where a scrolling gesture ran out of content before it
|
|
98
104
|
// hands the sheet the rest of the pull. Small enough to feel continuous with
|
|
@@ -253,6 +259,32 @@ function chainAtTop(chain) {
|
|
|
253
259
|
function chainAtBottom(chain) {
|
|
254
260
|
return chain.every(elementAtBottom);
|
|
255
261
|
}
|
|
262
|
+
function chainScrolls(chain) {
|
|
263
|
+
return chain.some(element => element.scrollHeight - element.clientHeight > 1);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* iOS rubber-bands a scroller past its end even under `overscroll-behavior:
|
|
268
|
+
* contain`. While the content sits at its end mid-pull, `none` holds it still,
|
|
269
|
+
* so only the sheet moves. Returns the undo.
|
|
270
|
+
*/
|
|
271
|
+
function holdAtEnd(chain) {
|
|
272
|
+
const previous = chain.map(element => element.style.overscrollBehaviorY);
|
|
273
|
+
for (const element of chain) {
|
|
274
|
+
element.style.overscrollBehaviorY = 'none';
|
|
275
|
+
}
|
|
276
|
+
return () => {
|
|
277
|
+
chain.forEach((element, index) => {
|
|
278
|
+
element.style.overscrollBehaviorY = previous[index];
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function releaseContentHold(armed) {
|
|
283
|
+
if (armed?.releaseContentHold != null) {
|
|
284
|
+
armed.releaseContentHold();
|
|
285
|
+
armed.releaseContentHold = null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
256
288
|
function visibleHeightForOffset(sheetHeight, offset, offscreenBlockEndInset) {
|
|
257
289
|
return Math.max(0, sheetHeight - offscreenBlockEndInset - offset);
|
|
258
290
|
}
|
|
@@ -775,7 +807,7 @@ export function useSheetGestures({
|
|
|
775
807
|
const baseLayoutOffset = settledLayoutOffsetRef.current;
|
|
776
808
|
dragStateRef.current = {
|
|
777
809
|
syntheticTouch,
|
|
778
|
-
pointerType:
|
|
810
|
+
pointerType: event.pointerType,
|
|
779
811
|
pointerId: event.pointerId,
|
|
780
812
|
startCoord: start,
|
|
781
813
|
lastCoord: event.clientY,
|
|
@@ -786,6 +818,7 @@ export function useSheetGestures({
|
|
|
786
818
|
}],
|
|
787
819
|
velocity: 0,
|
|
788
820
|
height: sheetHeight,
|
|
821
|
+
reserve: offscreenBlockEndInsetRef.current,
|
|
789
822
|
baseOffset: settledOffset,
|
|
790
823
|
baseLayoutOffset,
|
|
791
824
|
renderedOffset: settledOffset,
|
|
@@ -866,8 +899,9 @@ export function useSheetGestures({
|
|
|
866
899
|
const maxDetentOffset = offsets[offsets.length - 1];
|
|
867
900
|
let next;
|
|
868
901
|
if (raw < 0) {
|
|
869
|
-
//
|
|
870
|
-
|
|
902
|
+
// A touch device's reserve covers the whole stretch. The clamp binds
|
|
903
|
+
// only where the reserve is short.
|
|
904
|
+
next = state.pointerType === 'touch' ? Math.max(-state.reserve, rubberBand(raw, state.height - state.reserve, scroll.rubberBand.coefficient)) : Math.max(-OVERSCROLL_MAX, raw * OVERSCROLL_RESISTANCE);
|
|
871
905
|
} else if (raw > maxDetentOffset) {
|
|
872
906
|
// In the dismiss zone: no magnet, so it doesn't fight a drag-to-close.
|
|
873
907
|
next = raw;
|
|
@@ -1008,6 +1042,7 @@ export function useSheetGestures({
|
|
|
1008
1042
|
// hand-off and any drag in flight so nothing claims (or preventDefault()s)
|
|
1009
1043
|
// the gesture; the sheet returns to its detent.
|
|
1010
1044
|
const yieldToPinch = useCallback(target => {
|
|
1045
|
+
releaseContentHold(touchDragRef.current);
|
|
1011
1046
|
touchDragRef.current = null;
|
|
1012
1047
|
armedBodyRef.current = null;
|
|
1013
1048
|
cancelDrag(target);
|
|
@@ -1030,6 +1065,7 @@ export function useSheetGestures({
|
|
|
1030
1065
|
const asPointer = (touch, target) => ({
|
|
1031
1066
|
syntheticTouch: true,
|
|
1032
1067
|
pointerId: touch.identifier,
|
|
1068
|
+
pointerType: touchPointerType(touch),
|
|
1033
1069
|
clientY: touch.clientY,
|
|
1034
1070
|
timeStamp: Date.now(),
|
|
1035
1071
|
currentTarget: target,
|
|
@@ -1049,21 +1085,19 @@ export function useSheetGestures({
|
|
|
1049
1085
|
// scroll, but it is tracked all the same: the scroller can run out of
|
|
1050
1086
|
// content while the finger is still down (see onTouchMove). A touch
|
|
1051
1087
|
// inside a layer this sheet hosts is that layer's, never tracked here.
|
|
1088
|
+
releaseContentHold(touchDragRef.current);
|
|
1052
1089
|
if (!touch || isInsideNestedLayer(event.target, body)) {
|
|
1053
1090
|
touchDragRef.current = null;
|
|
1054
1091
|
return;
|
|
1055
1092
|
}
|
|
1056
1093
|
const scrollers = scrollChainUnder(event.target, body);
|
|
1057
1094
|
const top = chainAtTop(scrollers);
|
|
1058
|
-
//
|
|
1059
|
-
//
|
|
1060
|
-
//
|
|
1061
|
-
//
|
|
1062
|
-
//
|
|
1063
|
-
|
|
1064
|
-
// downward to scroll back would collapse the sheet instead. Leave the
|
|
1065
|
-
// gesture with the content.
|
|
1066
|
-
const bottom = chainAtBottom(scrollers) && activeOffsetRef.current > 0;
|
|
1095
|
+
// Claiming a pull up from its first move blocks the content's scroll for
|
|
1096
|
+
// the whole touch. So it is claimed here only below the tallest detent,
|
|
1097
|
+
// or over content that cannot scroll. At the tallest detent, a list at
|
|
1098
|
+
// its end keeps its touch. Its pull reaches the sheet through the
|
|
1099
|
+
// content-end hand-off below, and a reversal hands it back.
|
|
1100
|
+
const bottom = chainAtBottom(scrollers) && (activeOffsetRef.current > 0 || !chainScrolls(scrollers));
|
|
1067
1101
|
touchDragRef.current = {
|
|
1068
1102
|
id: touch.identifier,
|
|
1069
1103
|
startY: touch.clientY,
|
|
@@ -1071,7 +1105,8 @@ export function useSheetGestures({
|
|
|
1071
1105
|
top,
|
|
1072
1106
|
bottom,
|
|
1073
1107
|
contentEndY: null,
|
|
1074
|
-
promotedAtContentEnd: false
|
|
1108
|
+
promotedAtContentEnd: false,
|
|
1109
|
+
releaseContentHold: null
|
|
1075
1110
|
};
|
|
1076
1111
|
};
|
|
1077
1112
|
const onTouchMove = event => {
|
|
@@ -1098,6 +1133,7 @@ export function useSheetGestures({
|
|
|
1098
1133
|
// at once; a later pull past the end promotes again.
|
|
1099
1134
|
armed.contentEndY = null;
|
|
1100
1135
|
armed.promotedAtContentEnd = false;
|
|
1136
|
+
releaseContentHold(armed);
|
|
1101
1137
|
cancelDragRef.current(scroller);
|
|
1102
1138
|
return;
|
|
1103
1139
|
}
|
|
@@ -1127,6 +1163,7 @@ export function useSheetGestures({
|
|
|
1127
1163
|
const pullUpAtBottom = armed.bottom && delta < -DRAG_PROMOTION_SLOP && chainAtBottom(armed.scrollers);
|
|
1128
1164
|
if (pullDownAtTop || pullUpAtBottom) {
|
|
1129
1165
|
event.preventDefault();
|
|
1166
|
+
releaseContentHold(armed);
|
|
1130
1167
|
touchDragRef.current = null;
|
|
1131
1168
|
beginDragRef.current(asPointer(t, scroller), measureHeightRef.current(), armed.startY);
|
|
1132
1169
|
pointerMoveRef.current(asPointer(t, scroller));
|
|
@@ -1142,13 +1179,14 @@ export function useSheetGestures({
|
|
|
1142
1179
|
// cannot see this, and re-arming for a preventDefault() promotion would
|
|
1143
1180
|
// be useless anyway: once the browser has committed the gesture to
|
|
1144
1181
|
// scrolling, every remaining touchmove is non-cancelable. Nothing needs
|
|
1145
|
-
// cancelling either
|
|
1146
|
-
// upward travel scrolls nothing. Anchor at the point where the content
|
|
1182
|
+
// cancelling either: the hold clamps the scroller at its maximum, so
|
|
1183
|
+
// further upward travel scrolls nothing. Anchor at the point where the content
|
|
1147
1184
|
// ran out and give the sheet everything past it, so the pull continues
|
|
1148
1185
|
// into the sheet with no jump and no lost scrolling.
|
|
1149
|
-
if (
|
|
1186
|
+
if (chainAtBottom(armed.scrollers)) {
|
|
1150
1187
|
if (armed.contentEndY == null) {
|
|
1151
1188
|
armed.contentEndY = t.clientY;
|
|
1189
|
+
armed.releaseContentHold ??= holdAtEnd(armed.scrollers);
|
|
1152
1190
|
} else if (armed.contentEndY - t.clientY >= CONTENT_END_HANDOFF_SLOP) {
|
|
1153
1191
|
armed.promotedAtContentEnd = true;
|
|
1154
1192
|
beginDragRef.current(asPointer(t, scroller), measureHeightRef.current(), armed.contentEndY);
|
|
@@ -1156,9 +1194,11 @@ export function useSheetGestures({
|
|
|
1156
1194
|
}
|
|
1157
1195
|
} else {
|
|
1158
1196
|
armed.contentEndY = null;
|
|
1197
|
+
releaseContentHold(armed);
|
|
1159
1198
|
}
|
|
1160
1199
|
};
|
|
1161
1200
|
const onTouchEnd = event => {
|
|
1201
|
+
releaseContentHold(touchDragRef.current);
|
|
1162
1202
|
touchDragRef.current = null;
|
|
1163
1203
|
const pointerId = dragStateRef.current?.pointerId;
|
|
1164
1204
|
if (pointerId == null) {
|
package/dist/astryx.css
CHANGED
|
@@ -1916,7 +1916,7 @@
|
|
|
1916
1916
|
.xpa73km:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(100dvh - var(--_app-shell-header-height,0px))}
|
|
1917
1917
|
.xlgwz2i:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(2 * var(--spacing-3) + var(--text-code-size) * var(--text-code-leading))}
|
|
1918
1918
|
.x166xdbf:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(2 * var(--spacing-3) + var(--text-supporting-size) * var(--text-code-leading))}
|
|
1919
|
-
.
|
|
1919
|
+
.x1fqcpoh:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(var(--_sheet-budget) + var(--_sheet-reserve,48px))}
|
|
1920
1920
|
.x1uiybsj:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(var(--size-element-lg) - 4px)}
|
|
1921
1921
|
.x102lyln:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(var(--size-element-lg) - 8px)}
|
|
1922
1922
|
.x184gfjb:not(#\#):not(#\#):not(#\#):not(#\#){height:calc(var(--size-element-md) - 4px)}
|
|
@@ -1961,10 +1961,10 @@
|
|
|
1961
1961
|
.x6hpsvf:not(#\#):not(#\#):not(#\#):not(#\#){height:28px}
|
|
1962
1962
|
.x1nrll8i:not(#\#):not(#\#):not(#\#):not(#\#){left:50%}
|
|
1963
1963
|
.x1jyxor1:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:-1px}
|
|
1964
|
-
.x1if0o47:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:-48px}
|
|
1965
1964
|
.xat24cr:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:0}
|
|
1966
1965
|
.xlgak1e:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * (max(var(--_tab-strip-bleed),calc(-1 * var(--_tab-indicator-bottom,-1px)))))}
|
|
1967
1966
|
.x1z0f2p2:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * var(--_chat-composer-radius))}
|
|
1967
|
+
.xgwt18o:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * var(--_sheet-reserve,48px))}
|
|
1968
1968
|
.x13i4uq0:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * var(--astryx-number-input-padding-block-end,var(--astryx-number-input-padding,var(--spacing-1))))}
|
|
1969
1969
|
.xmtqr6q:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * var(--border-width))}
|
|
1970
1970
|
.x6h7pi7:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(-1 * var(--container-padding-block-end,0px))}
|
|
@@ -2007,7 +2007,7 @@
|
|
|
2007
2007
|
.x1xiyphd:not(#\#):not(#\#):not(#\#):not(#\#){max-height:240px}
|
|
2008
2008
|
.xuyqlj2:not(#\#):not(#\#):not(#\#):not(#\#){max-height:300px}
|
|
2009
2009
|
.xbhvqqn:not(#\#):not(#\#):not(#\#):not(#\#){max-height:calc(100% - var(--spacing-3))}
|
|
2010
|
-
.
|
|
2010
|
+
.xkche18:not(#\#):not(#\#):not(#\#):not(#\#){max-height:calc(92dvh + var(--_sheet-reserve,48px))}
|
|
2011
2011
|
.x3v4n1:not(#\#):not(#\#):not(#\#):not(#\#){max-height:calc(calc(100vh - var(--spacing-4) - var(--spacing-4) - var(--astryx-layer-inset-block-start, 0px) - var(--astryx-layer-inset-block-end, 0px)));max-height:calc(calc(100dvb - calc(max(var(--spacing-4), env(safe-area-inset-top, 0px)) + var(--astryx-layer-inset-block-start, 0px)) - calc(max(var(--spacing-4), env(safe-area-inset-bottom, 0px)) + var(--astryx-layer-inset-block-end, 0px))))}
|
|
2012
2012
|
.x1uh1i8a:not(#\#):not(#\#):not(#\#):not(#\#){max-height:min(300px,calc(100vh - var(--spacing-4) - var(--spacing-4) - var(--astryx-layer-inset-block-start, 0px) - var(--astryx-layer-inset-block-end, 0px)));max-height:min(300px,calc(100dvb - calc(max(var(--spacing-4), env(safe-area-inset-top, 0px)) + var(--astryx-layer-inset-block-start, 0px)) - calc(max(var(--spacing-4), env(safe-area-inset-bottom, 0px)) + var(--astryx-layer-inset-block-end, 0px))))}
|
|
2013
2013
|
.xa1agwl:not(#\#):not(#\#):not(#\#):not(#\#){max-height:min(480px,calc(100vh - var(--spacing-4) - var(--spacing-4) - var(--astryx-layer-inset-block-start, 0px) - var(--astryx-layer-inset-block-end, 0px)));max-height:min(480px,calc(100dvb - calc(max(var(--spacing-4), env(safe-area-inset-top, 0px)) + var(--astryx-layer-inset-block-start, 0px)) - calc(max(var(--spacing-4), env(safe-area-inset-bottom, 0px)) + var(--astryx-layer-inset-block-end, 0px))))}
|
|
@@ -2103,7 +2103,7 @@
|
|
|
2103
2103
|
.x1e4zzel:not(#\#):not(#\#):not(#\#):not(#\#){overscroll-behavior-y:contain}
|
|
2104
2104
|
.x18d9i69:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:0}
|
|
2105
2105
|
.x1j85h84:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:1px}
|
|
2106
|
-
.
|
|
2106
|
+
.x5559hn:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:calc(env(safe-area-inset-bottom,0px) + var(--_sheet-reserve,48px))}
|
|
2107
2107
|
.x9jihrk:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:calc(var(--_chat-composer-padding) + var(--_chat-composer-radius))}
|
|
2108
2108
|
.xvmia7e:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:calc(var(--container-padding-block-end,0px) + env(safe-area-inset-bottom,0px))}
|
|
2109
2109
|
.xbv1mwh:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:calc(var(--container-padding-block-end) - var(--border-width))}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/core",
|
|
3
|
-
"version": "0.7.9-canary.
|
|
3
|
+
"version": "0.7.9-canary.ef3db95",
|
|
4
4
|
"displayName": "Astryx Core",
|
|
5
5
|
"description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -875,9 +875,9 @@
|
|
|
875
875
|
"react-dom": ">=19.0.0"
|
|
876
876
|
},
|
|
877
877
|
"devDependencies": {
|
|
878
|
-
"@astryxdesign/a11y-spec": "0.7.9-canary.
|
|
879
|
-
"@astryxdesign/cli": "0.7.9-canary.
|
|
880
|
-
"@astryxdesign/interaction-harness": "0.7.9-canary.
|
|
878
|
+
"@astryxdesign/a11y-spec": "0.7.9-canary.ef3db95",
|
|
879
|
+
"@astryxdesign/cli": "0.7.9-canary.ef3db95",
|
|
880
|
+
"@astryxdesign/interaction-harness": "0.7.9-canary.ef3db95",
|
|
881
881
|
"@babel/cli": "^7.29.7",
|
|
882
882
|
"@babel/core": "^7.29.7",
|
|
883
883
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
useLayoutEffect,
|
|
27
27
|
useMemo,
|
|
28
28
|
useRef,
|
|
29
|
+
useSyncExternalStore,
|
|
29
30
|
type ReactNode,
|
|
30
31
|
} from 'react';
|
|
31
32
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -60,6 +61,7 @@ import {
|
|
|
60
61
|
paddingStyles,
|
|
61
62
|
spacingStepToToken,
|
|
62
63
|
} from '../Layout/padding.stylex';
|
|
64
|
+
import {subscribeInput} from '../utils/inputStream';
|
|
63
65
|
import type {SpacingStep} from '../utils/types';
|
|
64
66
|
import {
|
|
65
67
|
isValidSnapPoint,
|
|
@@ -82,8 +84,20 @@ const HEIGHT_BUDGETS = {
|
|
|
82
84
|
export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
|
|
83
85
|
export type {BottomSheetSnapPoint};
|
|
84
86
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
+
// The reserve: how far the sheet's surface reaches below the screen, so a
|
|
88
|
+
// pull past the top never shows the page under it.
|
|
89
|
+
// SYNC: OVERSCROLL_MAX in useSheetGestures.ts must not exceed MIN_RESERVE.
|
|
90
|
+
const MIN_RESERVE = 48;
|
|
91
|
+
// A finger can pull past the top by at most the viewport's height. The rubber
|
|
92
|
+
// band over a sheet as tall as the viewport then shows 35.5% of it.
|
|
93
|
+
const RESERVE_VIEWPORT_SHARE = 0.4;
|
|
94
|
+
|
|
95
|
+
function sheetReserve(viewportHeight: number): number {
|
|
96
|
+
return Math.max(
|
|
97
|
+
MIN_RESERVE,
|
|
98
|
+
Math.ceil(viewportHeight * RESERVE_VIEWPORT_SHARE),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
87
101
|
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
|
|
88
102
|
const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
89
103
|
// The floating handle bar's height. The bar is out of flow, so this is not
|
|
@@ -92,6 +106,22 @@ const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
|
92
106
|
// padding already provides.
|
|
93
107
|
const HANDLE_BAR_HEIGHT = spacingVars['--spacing-6'];
|
|
94
108
|
|
|
109
|
+
const BLOCK_SIZE_PROPERTIES = [
|
|
110
|
+
'height',
|
|
111
|
+
'minHeight',
|
|
112
|
+
'maxHeight',
|
|
113
|
+
'blockSize',
|
|
114
|
+
'minBlockSize',
|
|
115
|
+
'maxBlockSize',
|
|
116
|
+
] as const;
|
|
117
|
+
|
|
118
|
+
/** Whether StyleX styles hold any style: they can nest in arrays. */
|
|
119
|
+
function hasStyles(xstyle: unknown): boolean {
|
|
120
|
+
return Array.isArray(xstyle)
|
|
121
|
+
? xstyle.some(hasStyles)
|
|
122
|
+
: xstyle != null && typeof xstyle === 'object';
|
|
123
|
+
}
|
|
124
|
+
|
|
95
125
|
// Measure the viewport that the height budgets use. They are `dvh`, which
|
|
96
126
|
// the virtual keyboard does not shrink, so `visualViewport` would differ by
|
|
97
127
|
// the keyboard's height. `useMobileKeyboard` handles the keyboard and does
|
|
@@ -100,6 +130,14 @@ function layoutViewportHeight(): number {
|
|
|
100
130
|
return typeof window === 'undefined' ? 0 : window.innerHeight;
|
|
101
131
|
}
|
|
102
132
|
|
|
133
|
+
function subscribeToResize(onChange: () => void): () => void {
|
|
134
|
+
return subscribeInput(window, 'resize', onChange);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function subscribeToNothing(): () => void {
|
|
138
|
+
return () => {};
|
|
139
|
+
}
|
|
140
|
+
|
|
103
141
|
/**
|
|
104
142
|
* A stable identity for a set of snap points. Type-tagged, so the fraction
|
|
105
143
|
* `0.5` and the (invalid) string `'0.5'` cannot collide on one key.
|
|
@@ -159,8 +197,8 @@ const styles = stylex.create({
|
|
|
159
197
|
boxShadow: shadowVars['--shadow-high'],
|
|
160
198
|
outline: 'none',
|
|
161
199
|
overflow: 'hidden',
|
|
162
|
-
paddingBlockEnd: `calc(env(safe-area-inset-bottom, 0px) + ${
|
|
163
|
-
marginBlockEnd:
|
|
200
|
+
paddingBlockEnd: `calc(env(safe-area-inset-bottom, 0px) + var(--_sheet-reserve, ${MIN_RESERVE}px))`,
|
|
201
|
+
marginBlockEnd: `calc(-1 * var(--_sheet-reserve, ${MIN_RESERVE}px))`,
|
|
164
202
|
// Under reduced motion no transform runs. On a coarse primary pointer the
|
|
165
203
|
// entrance is an opacity cross-fade of at most 200 ms. A fine pointer gets
|
|
166
204
|
// the change at once (the 0.01s collapse).
|
|
@@ -340,11 +378,11 @@ const styles = stylex.create({
|
|
|
340
378
|
},
|
|
341
379
|
}),
|
|
342
380
|
budget: {
|
|
343
|
-
height: `calc(var(--_sheet-budget) + ${
|
|
381
|
+
height: `calc(var(--_sheet-budget) + var(--_sheet-reserve, ${MIN_RESERVE}px))`,
|
|
344
382
|
},
|
|
345
383
|
hugHeight: {
|
|
346
384
|
height: 'fit-content',
|
|
347
|
-
maxHeight: `calc(${HEIGHT_BUDGETS.hug} + ${
|
|
385
|
+
maxHeight: `calc(${HEIGHT_BUDGETS.hug} + var(--_sheet-reserve, ${MIN_RESERVE}px))`,
|
|
348
386
|
},
|
|
349
387
|
});
|
|
350
388
|
|
|
@@ -649,6 +687,24 @@ export function BottomSheetPanel({
|
|
|
649
687
|
|
|
650
688
|
// A caller's height owns the element's height: the drag never writes it.
|
|
651
689
|
const consumerHeight = style?.height;
|
|
690
|
+
// StyleX styles and a class name can size the sheet too. Their rules are
|
|
691
|
+
// only class names here, so any of them counts as a size.
|
|
692
|
+
const isSizedByCaller =
|
|
693
|
+
BLOCK_SIZE_PROPERTIES.some(property => style?.[property] != null) ||
|
|
694
|
+
hasStyles(xstyle) ||
|
|
695
|
+
(className != null && className !== '');
|
|
696
|
+
// Only a finger stretches the sheet past MIN_RESERVE, so a device with no
|
|
697
|
+
// touch pointer keeps the smallest reserve. So does a sheet the caller
|
|
698
|
+
// sizes, which nothing extends by the reserve; the stretch stops at it.
|
|
699
|
+
const hasTouchPointer = useMediaQuery('(any-pointer: coarse)');
|
|
700
|
+
const tracksViewport = isPresented && hasTouchPointer && !isSizedByCaller;
|
|
701
|
+
const viewportHeight = useSyncExternalStore(
|
|
702
|
+
tracksViewport ? subscribeToResize : subscribeToNothing,
|
|
703
|
+
() => (tracksViewport ? layoutViewportHeight() : 0),
|
|
704
|
+
() => 0,
|
|
705
|
+
);
|
|
706
|
+
const reserve =
|
|
707
|
+
viewportHeight > 0 ? sheetReserve(viewportHeight) : MIN_RESERVE;
|
|
652
708
|
const {
|
|
653
709
|
contentProps,
|
|
654
710
|
handleProps,
|
|
@@ -668,7 +724,7 @@ export function BottomSheetPanel({
|
|
|
668
724
|
isOpen: isInteractive,
|
|
669
725
|
isOpenRequested: isOpenRequested ?? isInteractive,
|
|
670
726
|
canDismiss: isSwipeDismissAllowed,
|
|
671
|
-
offscreenBlockEndInset:
|
|
727
|
+
offscreenBlockEndInset: reserve,
|
|
672
728
|
onDismiss,
|
|
673
729
|
snapHeights,
|
|
674
730
|
onTravelStart: () => {
|
|
@@ -931,6 +987,7 @@ export function BottomSheetPanel({
|
|
|
931
987
|
className,
|
|
932
988
|
{
|
|
933
989
|
['--_sheet-budget' as string]: budget,
|
|
990
|
+
['--_sheet-reserve' as string]: `${reserve}px`,
|
|
934
991
|
...(isInteractive
|
|
935
992
|
? gestureStyle
|
|
936
993
|
: isRetained || isClosing
|
|
@@ -64,6 +64,8 @@ import {
|
|
|
64
64
|
type UIEvent as ReactUIEvent,
|
|
65
65
|
} from 'react';
|
|
66
66
|
|
|
67
|
+
import {rubberBand} from '../motion/rubberBand';
|
|
68
|
+
import {scroll} from '../motion/uikit/scroll';
|
|
67
69
|
import {
|
|
68
70
|
computeDetentOffsets,
|
|
69
71
|
peekOffsetFor,
|
|
@@ -112,12 +114,19 @@ function isSyntheticTouch(event: ReactPointerEvent): boolean {
|
|
|
112
114
|
return (event as SyntheticTouchPointer).syntheticTouch === true;
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
type StylusTouch = Touch & {touchType?: string};
|
|
118
|
+
|
|
119
|
+
// An Apple Pencil raises touch events too, marked `stylus`. Its drag is a
|
|
120
|
+
// pen's, as on the grabber, where WebKit reports it as a pen.
|
|
121
|
+
function touchPointerType(touch: Touch): string {
|
|
122
|
+
return (touch as StylusTouch).touchType === 'stylus' ? 'pen' : 'touch';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// A mouse's stretch past fully open: a resisted fraction of the drag, capped
|
|
126
|
+
// at OVERSCROLL_MAX.
|
|
117
127
|
const OVERSCROLL_RESISTANCE = 0.35;
|
|
118
|
-
// SYNC: must
|
|
119
|
-
//
|
|
120
|
-
// import so it can be used inside stylex.create there.
|
|
128
|
+
// SYNC: must not exceed MIN_RESERVE in BottomSheetPanel.tsx, the smallest
|
|
129
|
+
// reserve the sheet keeps below the screen.
|
|
121
130
|
const OVERSCROLL_MAX = 48;
|
|
122
131
|
// Travel past the point where a scrolling gesture ran out of content before it
|
|
123
132
|
// hands the sheet the rest of the pull. Small enough to feel continuous with
|
|
@@ -308,6 +317,36 @@ function chainAtBottom(chain: ReadonlyArray<HTMLElement>): boolean {
|
|
|
308
317
|
return chain.every(elementAtBottom);
|
|
309
318
|
}
|
|
310
319
|
|
|
320
|
+
function chainScrolls(chain: ReadonlyArray<HTMLElement>): boolean {
|
|
321
|
+
return chain.some(element => element.scrollHeight - element.clientHeight > 1);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* iOS rubber-bands a scroller past its end even under `overscroll-behavior:
|
|
326
|
+
* contain`. While the content sits at its end mid-pull, `none` holds it still,
|
|
327
|
+
* so only the sheet moves. Returns the undo.
|
|
328
|
+
*/
|
|
329
|
+
function holdAtEnd(chain: ReadonlyArray<HTMLElement>): () => void {
|
|
330
|
+
const previous = chain.map(element => element.style.overscrollBehaviorY);
|
|
331
|
+
for (const element of chain) {
|
|
332
|
+
element.style.overscrollBehaviorY = 'none';
|
|
333
|
+
}
|
|
334
|
+
return () => {
|
|
335
|
+
chain.forEach((element, index) => {
|
|
336
|
+
element.style.overscrollBehaviorY = previous[index];
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function releaseContentHold(
|
|
342
|
+
armed: {releaseContentHold: (() => void) | null} | null,
|
|
343
|
+
): void {
|
|
344
|
+
if (armed?.releaseContentHold != null) {
|
|
345
|
+
armed.releaseContentHold();
|
|
346
|
+
armed.releaseContentHold = null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
311
350
|
function visibleHeightForOffset(
|
|
312
351
|
sheetHeight: number,
|
|
313
352
|
offset: number,
|
|
@@ -690,6 +729,8 @@ export function useSheetGestures({
|
|
|
690
729
|
samples: {t: number; y: number}[];
|
|
691
730
|
velocity: number;
|
|
692
731
|
height: number;
|
|
732
|
+
/** The surface kept below the screen when the drag began. */
|
|
733
|
+
reserve: number;
|
|
693
734
|
baseOffset: number;
|
|
694
735
|
baseLayoutOffset: number;
|
|
695
736
|
renderedOffset: number;
|
|
@@ -1171,7 +1212,7 @@ export function useSheetGestures({
|
|
|
1171
1212
|
const baseLayoutOffset = settledLayoutOffsetRef.current;
|
|
1172
1213
|
dragStateRef.current = {
|
|
1173
1214
|
syntheticTouch,
|
|
1174
|
-
pointerType:
|
|
1215
|
+
pointerType: event.pointerType,
|
|
1175
1216
|
pointerId: event.pointerId,
|
|
1176
1217
|
startCoord: start,
|
|
1177
1218
|
lastCoord: event.clientY,
|
|
@@ -1179,6 +1220,7 @@ export function useSheetGestures({
|
|
|
1179
1220
|
samples: [{t: event.timeStamp, y: event.clientY}],
|
|
1180
1221
|
velocity: 0,
|
|
1181
1222
|
height: sheetHeight,
|
|
1223
|
+
reserve: offscreenBlockEndInsetRef.current,
|
|
1182
1224
|
baseOffset: settledOffset,
|
|
1183
1225
|
baseLayoutOffset,
|
|
1184
1226
|
renderedOffset: settledOffset,
|
|
@@ -1279,8 +1321,19 @@ export function useSheetGestures({
|
|
|
1279
1321
|
const maxDetentOffset = offsets[offsets.length - 1];
|
|
1280
1322
|
let next: number;
|
|
1281
1323
|
if (raw < 0) {
|
|
1282
|
-
//
|
|
1283
|
-
|
|
1324
|
+
// A touch device's reserve covers the whole stretch. The clamp binds
|
|
1325
|
+
// only where the reserve is short.
|
|
1326
|
+
next =
|
|
1327
|
+
state.pointerType === 'touch'
|
|
1328
|
+
? Math.max(
|
|
1329
|
+
-state.reserve,
|
|
1330
|
+
rubberBand(
|
|
1331
|
+
raw,
|
|
1332
|
+
state.height - state.reserve,
|
|
1333
|
+
scroll.rubberBand.coefficient,
|
|
1334
|
+
),
|
|
1335
|
+
)
|
|
1336
|
+
: Math.max(-OVERSCROLL_MAX, raw * OVERSCROLL_RESISTANCE);
|
|
1284
1337
|
} else if (raw > maxDetentOffset) {
|
|
1285
1338
|
// In the dismiss zone: no magnet, so it doesn't fight a drag-to-close.
|
|
1286
1339
|
next = raw;
|
|
@@ -1482,6 +1535,8 @@ export function useSheetGestures({
|
|
|
1482
1535
|
// armed at `touchstart`. That drag never cancelled the native scroll, so
|
|
1483
1536
|
// it has to yield again if the finger comes back down.
|
|
1484
1537
|
promotedAtContentEnd: boolean;
|
|
1538
|
+
// Null while no hold is set.
|
|
1539
|
+
releaseContentHold: (() => void) | null;
|
|
1485
1540
|
} | null>(null);
|
|
1486
1541
|
const previousTouchHandlersRef = useRef<{
|
|
1487
1542
|
start: (e: TouchEvent) => void;
|
|
@@ -1495,6 +1550,7 @@ export function useSheetGestures({
|
|
|
1495
1550
|
// the gesture; the sheet returns to its detent.
|
|
1496
1551
|
const yieldToPinch = useCallback(
|
|
1497
1552
|
(target?: HTMLElement) => {
|
|
1553
|
+
releaseContentHold(touchDragRef.current);
|
|
1498
1554
|
touchDragRef.current = null;
|
|
1499
1555
|
armedBodyRef.current = null;
|
|
1500
1556
|
cancelDrag(target);
|
|
@@ -1522,6 +1578,7 @@ export function useSheetGestures({
|
|
|
1522
1578
|
({
|
|
1523
1579
|
syntheticTouch: true,
|
|
1524
1580
|
pointerId: touch.identifier,
|
|
1581
|
+
pointerType: touchPointerType(touch),
|
|
1525
1582
|
clientY: touch.clientY,
|
|
1526
1583
|
timeStamp: Date.now(),
|
|
1527
1584
|
currentTarget: target,
|
|
@@ -1542,21 +1599,21 @@ export function useSheetGestures({
|
|
|
1542
1599
|
// scroll, but it is tracked all the same: the scroller can run out of
|
|
1543
1600
|
// content while the finger is still down (see onTouchMove). A touch
|
|
1544
1601
|
// inside a layer this sheet hosts is that layer's, never tracked here.
|
|
1602
|
+
releaseContentHold(touchDragRef.current);
|
|
1545
1603
|
if (!touch || isInsideNestedLayer(event.target, body)) {
|
|
1546
1604
|
touchDragRef.current = null;
|
|
1547
1605
|
return;
|
|
1548
1606
|
}
|
|
1549
1607
|
const scrollers = scrollChainUnder(event.target, body);
|
|
1550
1608
|
const top = chainAtTop(scrollers);
|
|
1551
|
-
//
|
|
1552
|
-
//
|
|
1553
|
-
//
|
|
1554
|
-
//
|
|
1555
|
-
//
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
const bottom = chainAtBottom(scrollers) && activeOffsetRef.current > 0;
|
|
1609
|
+
// Claiming a pull up from its first move blocks the content's scroll for
|
|
1610
|
+
// the whole touch. So it is claimed here only below the tallest detent,
|
|
1611
|
+
// or over content that cannot scroll. At the tallest detent, a list at
|
|
1612
|
+
// its end keeps its touch. Its pull reaches the sheet through the
|
|
1613
|
+
// content-end hand-off below, and a reversal hands it back.
|
|
1614
|
+
const bottom =
|
|
1615
|
+
chainAtBottom(scrollers) &&
|
|
1616
|
+
(activeOffsetRef.current > 0 || !chainScrolls(scrollers));
|
|
1560
1617
|
touchDragRef.current = {
|
|
1561
1618
|
id: touch.identifier,
|
|
1562
1619
|
startY: touch.clientY,
|
|
@@ -1565,6 +1622,7 @@ export function useSheetGestures({
|
|
|
1565
1622
|
bottom,
|
|
1566
1623
|
contentEndY: null,
|
|
1567
1624
|
promotedAtContentEnd: false,
|
|
1625
|
+
releaseContentHold: null,
|
|
1568
1626
|
};
|
|
1569
1627
|
};
|
|
1570
1628
|
|
|
@@ -1594,6 +1652,7 @@ export function useSheetGestures({
|
|
|
1594
1652
|
// at once; a later pull past the end promotes again.
|
|
1595
1653
|
armed.contentEndY = null;
|
|
1596
1654
|
armed.promotedAtContentEnd = false;
|
|
1655
|
+
releaseContentHold(armed);
|
|
1597
1656
|
cancelDragRef.current(scroller);
|
|
1598
1657
|
return;
|
|
1599
1658
|
}
|
|
@@ -1627,6 +1686,7 @@ export function useSheetGestures({
|
|
|
1627
1686
|
chainAtBottom(armed.scrollers);
|
|
1628
1687
|
if (pullDownAtTop || pullUpAtBottom) {
|
|
1629
1688
|
event.preventDefault();
|
|
1689
|
+
releaseContentHold(armed);
|
|
1630
1690
|
touchDragRef.current = null;
|
|
1631
1691
|
beginDragRef.current(
|
|
1632
1692
|
asPointer(t, scroller),
|
|
@@ -1646,13 +1706,14 @@ export function useSheetGestures({
|
|
|
1646
1706
|
// cannot see this, and re-arming for a preventDefault() promotion would
|
|
1647
1707
|
// be useless anyway: once the browser has committed the gesture to
|
|
1648
1708
|
// scrolling, every remaining touchmove is non-cancelable. Nothing needs
|
|
1649
|
-
// cancelling either
|
|
1650
|
-
// upward travel scrolls nothing. Anchor at the point where the content
|
|
1709
|
+
// cancelling either: the hold clamps the scroller at its maximum, so
|
|
1710
|
+
// further upward travel scrolls nothing. Anchor at the point where the content
|
|
1651
1711
|
// ran out and give the sheet everything past it, so the pull continues
|
|
1652
1712
|
// into the sheet with no jump and no lost scrolling.
|
|
1653
|
-
if (
|
|
1713
|
+
if (chainAtBottom(armed.scrollers)) {
|
|
1654
1714
|
if (armed.contentEndY == null) {
|
|
1655
1715
|
armed.contentEndY = t.clientY;
|
|
1716
|
+
armed.releaseContentHold ??= holdAtEnd(armed.scrollers);
|
|
1656
1717
|
} else if (armed.contentEndY - t.clientY >= CONTENT_END_HANDOFF_SLOP) {
|
|
1657
1718
|
armed.promotedAtContentEnd = true;
|
|
1658
1719
|
beginDragRef.current(
|
|
@@ -1664,10 +1725,12 @@ export function useSheetGestures({
|
|
|
1664
1725
|
}
|
|
1665
1726
|
} else {
|
|
1666
1727
|
armed.contentEndY = null;
|
|
1728
|
+
releaseContentHold(armed);
|
|
1667
1729
|
}
|
|
1668
1730
|
};
|
|
1669
1731
|
|
|
1670
1732
|
const onTouchEnd = (event: TouchEvent) => {
|
|
1733
|
+
releaseContentHold(touchDragRef.current);
|
|
1671
1734
|
touchDragRef.current = null;
|
|
1672
1735
|
const pointerId = dragStateRef.current?.pointerId;
|
|
1673
1736
|
if (pointerId == null) {
|