@delacour/react-native-bottom-sheet 0.9.0-alpha.20261109205842 → 0.9.0
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/package.json +1 -1
- package/src/components/AGENTS.md +6 -0
- package/src/components/bottom-sheet.tsx +8 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/intent/resolve-intent.test.ts +15 -0
- package/src/core/intent/resolve-intent.ts +7 -1
- package/src/state/AGENTS.md +4 -0
- package/src/state/use-sheet-intents.ts +1 -0
package/package.json
CHANGED
package/src/components/AGENTS.md
CHANGED
|
@@ -57,6 +57,12 @@ path — swipe, overlay, `Close`, the ref, a controlled `isOpen: false` —
|
|
|
57
57
|
animates to the closed height, and the settle at `-1` is what flips `isOpen`
|
|
58
58
|
back and unmounts the children. Closing a sheet that is not open is nothing.
|
|
59
59
|
|
|
60
|
+
Opening a sheet that is still closing turns it round. A swipe, an overlay
|
|
61
|
+
press or a `Close` leaves `isOpen` true until the close settles, so the ref's
|
|
62
|
+
`open()` (and so `Trigger`) dispatches an `open` intent when `isOpen` is
|
|
63
|
+
already true, instead of a `setOpen(true)` that would change nothing. The
|
|
64
|
+
interrupted close never settles, so `onClose` does not fire.
|
|
65
|
+
|
|
60
66
|
The ref's `close()` checks the sheet's effective openness on the JS thread
|
|
61
67
|
before dispatching, so a `close()` while a queued open is still waiting on
|
|
62
68
|
layout clears the queue rather than racing it.
|
|
@@ -302,7 +302,14 @@ function BottomSheetRoot({
|
|
|
302
302
|
dispatch(request);
|
|
303
303
|
};
|
|
304
304
|
return {
|
|
305
|
-
|
|
305
|
+
// A swipe, an overlay press or a `Close` leaves `isOpen` true until the
|
|
306
|
+
// close settles, so `setOpen(true)` mid-close changes nothing and the
|
|
307
|
+
// press would be lost. Dispatch the intent instead: the resolver turns
|
|
308
|
+
// a closing sheet round, and does nothing to one that is open.
|
|
309
|
+
open: () => {
|
|
310
|
+
if (latestOpen.current) dispatch({ kind: "open" });
|
|
311
|
+
else setOpen(true);
|
|
312
|
+
},
|
|
306
313
|
close,
|
|
307
314
|
dismiss: close,
|
|
308
315
|
forceClose: () => {
|
package/src/core/AGENTS.md
CHANGED
|
@@ -47,7 +47,7 @@ at the moment a view needs it, by `geometry/position.ts`, and nowhere else.
|
|
|
47
47
|
| `geometry/clamp-height.ts` | W `clampHeight` — `NaN` collapses to closed |
|
|
48
48
|
| `geometry/detached-frame.ts` | `resolveDetached`, `DETACHED_DEFAULTS`, W `detachedFrame` — left, width, resting bottom |
|
|
49
49
|
| `backdrop/backdrop-opacity.ts` | W `backdropOpacity`, W `backdropInteractive` |
|
|
50
|
-
| `intent/resolve-intent.ts` | W `resolveIntent(state, intent)` — `wait` / `animate` / `jump` / `null`; open means `currentIndex ≥ 0` **or** `base` above the closed height, so a stale index never strands a visible sheet |
|
|
50
|
+
| `intent/resolve-intent.ts` | W `resolveIntent(state, intent)` — `wait` / `animate` / `jump` / `null`; open means `currentIndex ≥ 0` **or** `base` above the closed height, so a stale index never strands a visible sheet; an `open` while `closing` animates back to the initial index |
|
|
51
51
|
| `intent/layout-ready.ts` | W `isLayoutReady` |
|
|
52
52
|
| `haptic/crossed-snap-point.ts` | W `crossedSnapPoint` (boolean), W `snapPointUnder` (index) |
|
|
53
53
|
| `scroll/scroll-lock.ts` | W `shouldLockScroll`, W `contentPanDrivesSheet` |
|
|
@@ -10,10 +10,13 @@ const ready: IntentState = {
|
|
|
10
10
|
closedHeight: 0,
|
|
11
11
|
maxHeight: 800,
|
|
12
12
|
initialIndex: 0,
|
|
13
|
+
closing: false,
|
|
13
14
|
};
|
|
14
15
|
const open: IntentState = { ...ready, currentIndex: 1, base: 400 };
|
|
15
16
|
/** A sheet visibly open whose settled index never caught up — a release the list owned. */
|
|
16
17
|
const staleClosed: IntentState = { ...ready, currentIndex: -1, base: 800 };
|
|
18
|
+
/** Part-way down a close animation: still visible, on its way to the closed height. */
|
|
19
|
+
const closing: IntentState = { ...ready, currentIndex: -1, base: 150, closing: true };
|
|
17
20
|
const unmeasured: IntentState = { ...ready, layoutReady: false, snapPoints: [] };
|
|
18
21
|
|
|
19
22
|
const intent = (kind: SheetIntent["kind"], extra: Record<string, unknown> = {}): SheetIntent =>
|
|
@@ -39,6 +42,18 @@ describe("resolveIntent", () => {
|
|
|
39
42
|
expect(resolveIntent(staleClosed, intent("open"))).toBeNull();
|
|
40
43
|
});
|
|
41
44
|
|
|
45
|
+
test("turns a closing sheet round to its initial index", () => {
|
|
46
|
+
expect(resolveIntent(closing, intent("open"))).toEqual({ action: "animate", target: 200 });
|
|
47
|
+
expect(resolveIntent({ ...closing, initialIndex: 2 }, intent("open"))).toEqual({
|
|
48
|
+
action: "animate",
|
|
49
|
+
target: 800,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("a closing sheet above its initial snap point still reopens", () => {
|
|
54
|
+
expect(resolveIntent({ ...closing, base: 600 }, intent("open"))).toEqual({ action: "animate", target: 200 });
|
|
55
|
+
});
|
|
56
|
+
|
|
42
57
|
test("with nothing to open to there is nothing to do", () => {
|
|
43
58
|
expect(resolveIntent({ ...ready, snapPoints: [] }, intent("open"))).toBeNull();
|
|
44
59
|
});
|
|
@@ -21,6 +21,12 @@ export type IntentState = {
|
|
|
21
21
|
maxHeight: number;
|
|
22
22
|
/** The index `open` targets. */
|
|
23
23
|
initialIndex: number;
|
|
24
|
+
/**
|
|
25
|
+
* A close animation is running. The sheet is still visible, so `base` says
|
|
26
|
+
* open, but an `open` must turn it round rather than read it as open and
|
|
27
|
+
* do nothing.
|
|
28
|
+
*/
|
|
29
|
+
closing: boolean;
|
|
24
30
|
};
|
|
25
31
|
|
|
26
32
|
/**
|
|
@@ -64,7 +70,7 @@ export function resolveIntent(state: IntentState, intent: SheetIntent): IntentRe
|
|
|
64
70
|
if (intent.kind === "forceClose") {
|
|
65
71
|
return isOpen ? { action: "jump", target: state.closedHeight } : null;
|
|
66
72
|
}
|
|
67
|
-
if (intent.kind === "open" && isOpen) return null;
|
|
73
|
+
if (intent.kind === "open" && isOpen && !state.closing) return null;
|
|
68
74
|
if (!state.layoutReady) return { action: "wait" };
|
|
69
75
|
|
|
70
76
|
if (intent.kind === "open") {
|
package/src/state/AGENTS.md
CHANGED
|
@@ -44,6 +44,10 @@ The resolver is told the sheet's **effective** index: the settled one, or the
|
|
|
44
44
|
running animation's target. Without that a `close()` during the open animation
|
|
45
45
|
would see a closed sheet, resolve to nothing, and let the sheet finish opening.
|
|
46
46
|
|
|
47
|
+
It is also told whether a close animation is running (`closing`). Mid-close
|
|
48
|
+
`base` is still above the closed height, so without it an `open` would read
|
|
49
|
+
the sheet as open and be dropped.
|
|
50
|
+
|
|
47
51
|
The first open a sheet resolves is reported as `"mount"` and, with
|
|
48
52
|
`animateOnMount: false`, jumps. `mountPending` is that flag.
|
|
49
53
|
|
|
@@ -95,6 +95,7 @@ export function useSheetIntents(
|
|
|
95
95
|
closedHeight: geometry.closedHeight.value,
|
|
96
96
|
maxHeight: geometry.maxHeight.value,
|
|
97
97
|
initialIndex: state.config.value.initialIndex,
|
|
98
|
+
closing: state.animStatus.value === ANIM_STATUS.RUNNING && effectiveIndex < 0,
|
|
98
99
|
},
|
|
99
100
|
intent
|
|
100
101
|
);
|