@asaddevworld/sheet-stack 0.0.0-stage → 0.1.1

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.
Files changed (55) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +150 -2
  3. package/lib/module/Backdrop.js +30 -0
  4. package/lib/module/Backdrop.js.map +1 -0
  5. package/lib/module/Sheet.js +303 -0
  6. package/lib/module/Sheet.js.map +1 -0
  7. package/lib/module/SheetHost.js +94 -0
  8. package/lib/module/SheetHost.js.map +1 -0
  9. package/lib/module/SheetProvider.js +76 -0
  10. package/lib/module/SheetProvider.js.map +1 -0
  11. package/lib/module/SheetScrollView.js +51 -0
  12. package/lib/module/SheetScrollView.js.map +1 -0
  13. package/lib/module/context.js +33 -0
  14. package/lib/module/context.js.map +1 -0
  15. package/lib/module/defaults.js +34 -0
  16. package/lib/module/defaults.js.map +1 -0
  17. package/lib/module/index.js +7 -0
  18. package/lib/module/index.js.map +1 -0
  19. package/lib/module/package.json +1 -0
  20. package/lib/module/types.js +4 -0
  21. package/lib/module/types.js.map +1 -0
  22. package/lib/module/utils/snap.js +93 -0
  23. package/lib/module/utils/snap.js.map +1 -0
  24. package/lib/typescript/package.json +1 -0
  25. package/lib/typescript/src/Backdrop.d.ts +9 -0
  26. package/lib/typescript/src/Backdrop.d.ts.map +1 -0
  27. package/lib/typescript/src/Sheet.d.ts +18 -0
  28. package/lib/typescript/src/Sheet.d.ts.map +1 -0
  29. package/lib/typescript/src/SheetHost.d.ts +2 -0
  30. package/lib/typescript/src/SheetHost.d.ts.map +1 -0
  31. package/lib/typescript/src/SheetProvider.d.ts +10 -0
  32. package/lib/typescript/src/SheetProvider.d.ts.map +1 -0
  33. package/lib/typescript/src/SheetScrollView.d.ts +7 -0
  34. package/lib/typescript/src/SheetScrollView.d.ts.map +1 -0
  35. package/lib/typescript/src/context.d.ts +20 -0
  36. package/lib/typescript/src/context.d.ts.map +1 -0
  37. package/lib/typescript/src/defaults.d.ts +13 -0
  38. package/lib/typescript/src/defaults.d.ts.map +1 -0
  39. package/lib/typescript/src/index.d.ts +6 -0
  40. package/lib/typescript/src/index.d.ts.map +1 -0
  41. package/lib/typescript/src/types.d.ts +66 -0
  42. package/lib/typescript/src/types.d.ts.map +1 -0
  43. package/lib/typescript/src/utils/snap.d.ts +28 -0
  44. package/lib/typescript/src/utils/snap.d.ts.map +1 -0
  45. package/package.json +163 -4
  46. package/src/Backdrop.tsx +32 -0
  47. package/src/Sheet.tsx +404 -0
  48. package/src/SheetHost.tsx +132 -0
  49. package/src/SheetProvider.tsx +76 -0
  50. package/src/SheetScrollView.tsx +50 -0
  51. package/src/context.tsx +52 -0
  52. package/src/defaults.ts +38 -0
  53. package/src/index.tsx +13 -0
  54. package/src/types.ts +78 -0
  55. package/src/utils/snap.ts +101 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asad Ali
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
1
+ # rn-sheet-stack
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@asaddevworld/sheet-stack)](https://www.npmjs.com/package/@asaddevworld/sheet-stack)
4
+
5
+ Stackable bottom sheets for React Native. One provider, one hook. Sheets stack like cards: each new sheet slides up and the one beneath scales back and dims. Snap points, drag to dismiss, scroll hand-off, keyboard lift, Android back button, reduced motion. Everything animates on the UI thread with Reanimated and Gesture Handler.
6
+
7
+
8
+
9
+ <a href="https://github.com/asadDevWorld/rn-sheet-stack/blob/main/docs/demo.mp4"><img src="https://raw.githubusercontent.com/asadDevWorld/rn-sheet-stack/main/docs/demo.gif" width="300" alt="rn-sheet-stack demo" /></a>
10
+
11
+
12
+
13
+ _Demo recorded on the iOS Simulator from the example app, shown at 2x speed. Full video: [docs/demo.mp4](docs/demo.mp4)._
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install @asaddevworld/sheet-stack react-native-reanimated react-native-worklets react-native-gesture-handler react-native-safe-area-context
19
+ ```
20
+
21
+ With Expo:
22
+
23
+ ```bash
24
+ npx expo install @asaddevworld/sheet-stack react-native-reanimated react-native-worklets react-native-gesture-handler react-native-safe-area-context
25
+ ```
26
+
27
+ Requires React Native 0.76 or newer, Reanimated 4, and Gesture Handler 3. Follow their installation guides once (Babel plugin for Worklets, `GestureHandlerRootView` at the root).
28
+
29
+ ## Setup
30
+
31
+ Wrap the app once:
32
+
33
+ ```tsx
34
+ import { GestureHandlerRootView } from 'react-native-gesture-handler';
35
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
36
+ import { SheetProvider } from '@asaddevworld/sheet-stack';
37
+
38
+ export default function App() {
39
+ return (
40
+ <GestureHandlerRootView style={{ flex: 1 }}>
41
+ <SafeAreaProvider>
42
+ <SheetProvider>
43
+ <Root />
44
+ </SheetProvider>
45
+ </SafeAreaProvider>
46
+ </GestureHandlerRootView>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ```tsx
54
+ import { useSheets, SheetScrollView } from '@asaddevworld/sheet-stack';
55
+
56
+ function PickCity() {
57
+ const sheets = useSheets();
58
+
59
+ return (
60
+ <Button
61
+ title="Choose"
62
+ onPress={() =>
63
+ sheets.push({
64
+ snapPoints: ['45%', '92%'],
65
+ render: ({ dismiss }) => (
66
+ <SheetScrollView>
67
+ {cities.map((city) => (
68
+ <Row key={city} label={city} onPress={dismiss} />
69
+ ))}
70
+ </SheetScrollView>
71
+ ),
72
+ })
73
+ }
74
+ />
75
+ );
76
+ }
77
+ ```
78
+
79
+ Stack a confirmation on top of it from anywhere, including from inside the first sheet:
80
+
81
+ ```tsx
82
+ sheets.push({
83
+ render: ({ dismiss }) => (
84
+ <Confirm onYes={() => sheets.popAll()} onNo={dismiss} />
85
+ ),
86
+ });
87
+ ```
88
+
89
+ ## API
90
+
91
+ ### `useSheets()`
92
+
93
+ | member | type | description |
94
+ |---|---|---|
95
+ | `push(options)` | `(SheetOptions) => SheetId` | Open a sheet on top of the stack. |
96
+ | `pop()` | `() => void` | Close the top sheet. |
97
+ | `dismiss(id)` | `(SheetId) => void` | Close a specific sheet. |
98
+ | `popAll()` | `() => void` | Close every sheet. |
99
+ | `update(id, patch)` | `(SheetId, Partial<SheetOptions>) => void` | Change the options of an open sheet, for example make it dismissible after a form is valid. |
100
+ | `stack` | `SheetId[]` | Ids of the open sheets, bottom to top. Reactive. |
101
+
102
+ ### `SheetOptions`
103
+
104
+ | option | type | default | description |
105
+ |---|---|---|---|
106
+ | `render` | `(ctx) => ReactNode` | required | Sheet content. `ctx` has `id`, `index`, `isTop`, `dismiss()`. |
107
+ | `snapPoints` | `(number \| \`${n}%\` \| 'auto')[]` | `['auto']` | Heights the sheet can rest at. `'auto'` fits the content. |
108
+ | `initialSnap` | `number` | `0` | Index into `snapPoints` to open at. |
109
+ | `dismissible` | `boolean` | `true` | Drag down, backdrop tap and Android back close the sheet. |
110
+ | `backdropOpacity` | `number` | `0.4` | Dim behind the top sheet. |
111
+ | `handle` | `boolean` | `true` | Show the grab handle. |
112
+ | `keyboardBehavior` | `'padding' \| 'none'` | `'padding'` | Lift the sheet with the keyboard. |
113
+ | `onDismiss` | `() => void` | | Called after the close animation. |
114
+ | `onSnap` | `(index) => void` | | Called when the sheet settles at a snap point. |
115
+ | `style` | `ViewStyle` | | Sheet container style (background, radius). |
116
+ | `stackScale` | `number` | `0.94` | Scale of the sheet beneath when a new one opens. |
117
+ | `stackOffset` | `number` | `12` | Pixels the sheet beneath moves up when a new one opens. |
118
+
119
+ ### `useSheet()`
120
+
121
+ Inside sheet content, returns the same `{ id, index, isTop, dismiss }` as the render context. Handy for components nested deep in the sheet.
122
+
123
+ ### `SheetScrollView`
124
+
125
+ A `ScrollView` for sheet content. When the list is scrolled to the top and the user drags down, the drag goes to the sheet, so it collapses to the lower snap point or dismisses. Any other time it scrolls normally. Pass any `ScrollView` props.
126
+
127
+ ## Behaviour notes
128
+
129
+ - Release position and velocity pick the nearest snap point. A fast downward fling or a release well below the lowest snap point dismisses, when `dismissible`.
130
+ - Pulling above the top snap point rubber-bands. A non-dismissible sheet rubber-bands at its lowest point instead of closing.
131
+ - Up to three sheets are drawn in the stack; deeper ones fade out and come back as the top ones close.
132
+ - The hardware back button on Android closes the top sheet only.
133
+ - When the OS reduce-motion setting is on, springs become short timed animations.
134
+ - The top sheet is announced as modal to screen readers, and the backdrop is a "Close sheet" button.
135
+
136
+ ## Example app
137
+
138
+ ```bash
139
+ yarn
140
+ yarn example ios
141
+ ```
142
+
143
+ The example has four demos: Basics (snap points and scroll hand-off), Stack (three sheets deep), Form (keyboard lift, not dismissible until submitted), and Playground (tune scale, offset and backdrop live).
144
+
145
+ ## Credits
146
+
147
+ Inspired by the stacked sheet demos by Enzo Mangano at reactiive.io. Implemented from scratch for this package.
148
+
149
+ ## License
150
+
151
+ MIT © Asad Ali
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { Pressable, StyleSheet } from 'react-native';
4
+ import Animated, { useAnimatedStyle } from 'react-native-reanimated';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export function Backdrop({
7
+ opacity,
8
+ active,
9
+ onPress
10
+ }) {
11
+ const style = useAnimatedStyle(() => ({
12
+ opacity: opacity.value
13
+ }));
14
+ return /*#__PURE__*/_jsx(Animated.View, {
15
+ style: [StyleSheet.absoluteFill, styles.backdrop, style],
16
+ pointerEvents: active ? 'auto' : 'none',
17
+ children: /*#__PURE__*/_jsx(Pressable, {
18
+ style: StyleSheet.absoluteFill,
19
+ onPress: onPress,
20
+ accessibilityRole: "button",
21
+ accessibilityLabel: "Close sheet"
22
+ })
23
+ });
24
+ }
25
+ const styles = StyleSheet.create({
26
+ backdrop: {
27
+ backgroundColor: '#000'
28
+ }
29
+ });
30
+ //# sourceMappingURL=Backdrop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Pressable","StyleSheet","Animated","useAnimatedStyle","jsx","_jsx","Backdrop","opacity","active","onPress","style","value","View","absoluteFill","styles","backdrop","pointerEvents","children","accessibilityRole","accessibilityLabel","create","backgroundColor"],"sourceRoot":"../../src","sources":["Backdrop.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,UAAU,QAAQ,cAAc;AACpD,OAAOC,QAAQ,IACbC,gBAAgB,QAEX,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQjC,OAAO,SAASC,QAAQA,CAAC;EAAEC,OAAO;EAAEC,MAAM;EAAEC;AAAe,CAAC,EAAE;EAC5D,MAAMC,KAAK,GAAGP,gBAAgB,CAAC,OAAO;IAAEI,OAAO,EAAEA,OAAO,CAACI;EAAM,CAAC,CAAC,CAAC;EAClE,oBACEN,IAAA,CAACH,QAAQ,CAACU,IAAI;IACZF,KAAK,EAAE,CAACT,UAAU,CAACY,YAAY,EAAEC,MAAM,CAACC,QAAQ,EAAEL,KAAK,CAAE;IACzDM,aAAa,EAAER,MAAM,GAAG,MAAM,GAAG,MAAO;IAAAS,QAAA,eAExCZ,IAAA,CAACL,SAAS;MACRU,KAAK,EAAET,UAAU,CAACY,YAAa;MAC/BJ,OAAO,EAAEA,OAAQ;MACjBS,iBAAiB,EAAC,QAAQ;MAC1BC,kBAAkB,EAAC;IAAa,CACjC;EAAC,CACW,CAAC;AAEpB;AAEA,MAAML,MAAM,GAAGb,UAAU,CAACmB,MAAM,CAAC;EAC/BL,QAAQ,EAAE;IAAEM,eAAe,EAAE;EAAO;AACtC,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { StyleSheet, View } from 'react-native';
5
+ import { GestureDetector, useNativeGesture, usePanGesture } from 'react-native-gesture-handler';
6
+ import Animated, { Extrapolation, ReduceMotion, cancelAnimation, interpolate, runOnJS, useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
7
+ import { SheetInstanceContext } from "./context.js";
8
+ import { pickSnapTarget, resolveSnapHeights, rubberBand } from "./utils/snap.js";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ export const HANDLE_HEIGHT = 24;
11
+ const NO_HANDLE_HEIGHT = 8;
12
+ /** Extra background below the sheet so a rubber-band pull never shows a gap. */
13
+ const OVERSHOOT = 160;
14
+ const ACTIVATE_DISTANCE = 6;
15
+ const OPEN_SPRING = {
16
+ damping: 34,
17
+ stiffness: 340,
18
+ mass: 1,
19
+ reduceMotion: ReduceMotion.System
20
+ };
21
+ const CLOSE_SPRING = {
22
+ damping: 40,
23
+ stiffness: 420,
24
+ mass: 1,
25
+ overshootClamping: true,
26
+ reduceMotion: ReduceMotion.System
27
+ };
28
+ export function Sheet({
29
+ entry,
30
+ index,
31
+ depth,
32
+ isTop,
33
+ containerHeight,
34
+ topInset,
35
+ bottomInset,
36
+ keyboardHeight,
37
+ onClosed,
38
+ requestDismiss
39
+ }) {
40
+ const {
41
+ options
42
+ } = entry;
43
+ const handleHeight = options.handle ? HANDLE_HEIGHT : NO_HANDLE_HEIGHT;
44
+ const needsMeasure = options.snapPoints.includes('auto');
45
+ const [contentHeight, setContentHeight] = useState(0);
46
+ const [measured, setMeasured] = useState(!needsMeasure);
47
+ const maxHeight = Math.max(0, containerHeight - topInset);
48
+ const snapHeights = useMemo(() => resolveSnapHeights(options.snapPoints, containerHeight, maxHeight, contentHeight + handleHeight + bottomInset), [options.snapPoints, containerHeight, maxHeight, contentHeight, handleHeight, bottomInset]);
49
+ const maxSnapHeight = snapHeights[snapHeights.length - 1] ?? 0;
50
+ const closedY = containerHeight;
51
+ const snapYs = useMemo(() => snapHeights.map(h => containerHeight - h), [snapHeights, containerHeight]);
52
+ const lowestY = snapYs[0] ?? closedY;
53
+ const topY = snapYs[snapYs.length - 1] ?? closedY;
54
+ const ready = containerHeight > 0 && measured;
55
+ const isOpen = entry.status === 'open';
56
+ const y = useSharedValue(closedY);
57
+ const depthSv = useSharedValue(depth);
58
+ const dragStartY = useSharedValue(0);
59
+ const moved = useSharedValue(false);
60
+ const dragging = useSharedValue(false);
61
+ const scrollY = useSharedValue(0);
62
+ const hasScroll = useSharedValue(false);
63
+ const snapYsSv = useSharedValue(snapYs);
64
+ const topYSv = useSharedValue(topY);
65
+ const lowestYSv = useSharedValue(lowestY);
66
+ const closedYSv = useSharedValue(closedY);
67
+ const dismissibleSv = useSharedValue(options.dismissible);
68
+ const currentSnap = useSharedValue(options.initialSnap);
69
+ const opened = useRef(false);
70
+ const closing = useRef(false);
71
+ useEffect(() => {
72
+ snapYsSv.value = snapYs;
73
+ topYSv.value = topY;
74
+ lowestYSv.value = lowestY;
75
+ closedYSv.value = closedY;
76
+ dismissibleSv.value = options.dismissible;
77
+ }, [snapYs, topY, lowestY, closedY, options.dismissible, snapYsSv, topYSv, lowestYSv, closedYSv, dismissibleSv]);
78
+ const onSnapRef = useRef(options.onSnap);
79
+ onSnapRef.current = options.onSnap;
80
+ const notifySnap = useCallback(snapIndex => {
81
+ onSnapRef.current?.(snapIndex);
82
+ }, []);
83
+
84
+ // Open on first ready render, then keep the sheet on its snap point if the points change.
85
+ useEffect(() => {
86
+ if (!ready || !isOpen) {
87
+ return;
88
+ }
89
+ if (!opened.current) {
90
+ opened.current = true;
91
+ const initial = options.initialSnap;
92
+ currentSnap.value = initial;
93
+ y.value = withSpring(snapYs[initial] ?? lowestY, OPEN_SPRING, finished => {
94
+ if (finished) {
95
+ runOnJS(notifySnap)(initial);
96
+ }
97
+ });
98
+ return;
99
+ }
100
+ if (dragging.value) {
101
+ return;
102
+ }
103
+ const snapIndex = Math.min(currentSnap.value, snapYs.length - 1);
104
+ y.value = withSpring(snapYs[snapIndex] ?? lowestY, OPEN_SPRING);
105
+ }, [ready, isOpen, snapYs, lowestY, options.initialSnap, y, currentSnap, dragging, notifySnap]);
106
+
107
+ // Close when the provider marks the entry as closing.
108
+ useEffect(() => {
109
+ if (isOpen || closing.current) {
110
+ return;
111
+ }
112
+ closing.current = true;
113
+ const finish = () => {
114
+ onClosed(entry.id);
115
+ options.onDismiss?.();
116
+ };
117
+ y.value = withSpring(closedY, CLOSE_SPRING, () => {
118
+ runOnJS(finish)();
119
+ });
120
+ }, [isOpen, closedY, entry.id, options, onClosed, y]);
121
+ useEffect(() => {
122
+ depthSv.value = withSpring(depth, OPEN_SPRING);
123
+ }, [depth, depthSv]);
124
+ const scrollGesture = useNativeGesture();
125
+ const pan = usePanGesture({
126
+ enabled: ready && isOpen,
127
+ activeOffsetY: [-ACTIVATE_DISTANCE, ACTIVATE_DISTANCE],
128
+ simultaneousWith: scrollGesture,
129
+ onBegin: () => {
130
+ 'worklet';
131
+
132
+ cancelAnimation(y);
133
+ dragStartY.value = y.value;
134
+ moved.value = false;
135
+ dragging.value = true;
136
+ },
137
+ onUpdate: e => {
138
+ 'worklet';
139
+
140
+ // The scroll view owns the gesture while it has content scrolled away from the top.
141
+ if (hasScroll.value && !moved.value && scrollY.value > 0.5) {
142
+ dragStartY.value = y.value - e.translationY;
143
+ return;
144
+ }
145
+ let next = dragStartY.value + e.translationY;
146
+ if (next < topYSv.value) {
147
+ if (hasScroll.value && !moved.value) {
148
+ // At the top with a scroll view: an upward drag scrolls content instead.
149
+ dragStartY.value = y.value - e.translationY;
150
+ return;
151
+ }
152
+ next = topYSv.value - rubberBand(topYSv.value - next, containerHeight);
153
+ }
154
+ if (!dismissibleSv.value && next > lowestYSv.value) {
155
+ next = lowestYSv.value + rubberBand(next - lowestYSv.value, containerHeight, 0.3);
156
+ }
157
+ if (Math.abs(next - y.value) > 0.01) {
158
+ moved.value = true;
159
+ }
160
+ y.value = next;
161
+ },
162
+ onDeactivate: e => {
163
+ 'worklet';
164
+
165
+ dragging.value = false;
166
+ if (!moved.value) {
167
+ return;
168
+ }
169
+ const target = pickSnapTarget({
170
+ y: y.value,
171
+ velocityY: e.velocityY,
172
+ snapYs: snapYsSv.value,
173
+ closedY: closedYSv.value,
174
+ dismissible: dismissibleSv.value
175
+ });
176
+ if (target.index === -1) {
177
+ y.value = withSpring(closedYSv.value, CLOSE_SPRING);
178
+ runOnJS(requestDismiss)(entry.id);
179
+ return;
180
+ }
181
+ currentSnap.value = target.index;
182
+ y.value = withSpring(target.y, {
183
+ ...OPEN_SPRING,
184
+ velocity: e.velocityY
185
+ }, finished => {
186
+ if (finished) {
187
+ runOnJS(notifySnap)(target.index);
188
+ }
189
+ });
190
+ },
191
+ onFinalize: () => {
192
+ 'worklet';
193
+
194
+ dragging.value = false;
195
+ }
196
+ });
197
+ const keyboardPadding = options.keyboardBehavior === 'padding';
198
+ const {
199
+ stackOffset,
200
+ stackScale
201
+ } = options;
202
+ const sheetStyle = useAnimatedStyle(() => {
203
+ const d = depthSv.value;
204
+ const progress = interpolate(y.value, [closedY, lowestY], [0, 1], Extrapolation.CLAMP);
205
+ const lift = keyboardPadding ? keyboardHeight.value * progress : 0;
206
+ const base = Math.max(topInset, y.value - lift);
207
+ return {
208
+ height: maxSnapHeight + OVERSHOOT,
209
+ opacity: d > 2.5 ? 0 : 1,
210
+ transform: [{
211
+ translateY: base - stackOffset * d
212
+ }, {
213
+ scale: Math.pow(stackScale, d)
214
+ }]
215
+ };
216
+ });
217
+ const dimStyle = useAnimatedStyle(() => ({
218
+ opacity: interpolate(depthSv.value, [0, 1, 2], [0, 0.18, 0.3], Extrapolation.CLAMP)
219
+ }));
220
+ const onContentLayout = useCallback(e => {
221
+ const h = Math.round(e.nativeEvent.layout.height);
222
+ setContentHeight(prev => prev === h ? prev : h);
223
+ setMeasured(true);
224
+ }, []);
225
+ const contentStyle = needsMeasure ? {
226
+ maxHeight: Math.max(0, maxHeight - handleHeight - bottomInset)
227
+ } : {
228
+ height: Math.max(0, maxSnapHeight - handleHeight - bottomInset)
229
+ };
230
+ const renderContext = useMemo(() => ({
231
+ id: entry.id,
232
+ index,
233
+ isTop,
234
+ dismiss: () => requestDismiss(entry.id)
235
+ }), [entry.id, index, isTop, requestDismiss]);
236
+ const instance = useMemo(() => ({
237
+ ...renderContext,
238
+ y,
239
+ topY: topYSv,
240
+ scrollY,
241
+ hasScroll,
242
+ scrollGesture
243
+ }), [renderContext, y, topYSv, scrollY, hasScroll, scrollGesture]);
244
+ return /*#__PURE__*/_jsx(SheetInstanceContext.Provider, {
245
+ value: instance,
246
+ children: /*#__PURE__*/_jsx(GestureDetector, {
247
+ gesture: pan,
248
+ children: /*#__PURE__*/_jsxs(Animated.View, {
249
+ style: [styles.sheet, {
250
+ paddingBottom: bottomInset + OVERSHOOT
251
+ }, options.style, sheetStyle],
252
+ accessibilityViewIsModal: isTop,
253
+ importantForAccessibility: isTop ? 'yes' : 'no-hide-descendants',
254
+ children: [options.handle ? /*#__PURE__*/_jsx(View, {
255
+ style: styles.handleRow,
256
+ children: /*#__PURE__*/_jsx(View, {
257
+ style: styles.handle
258
+ })
259
+ }) : /*#__PURE__*/_jsx(View, {
260
+ style: styles.noHandle
261
+ }), /*#__PURE__*/_jsx(View, {
262
+ style: contentStyle,
263
+ onLayout: needsMeasure ? onContentLayout : undefined,
264
+ children: options.render(renderContext)
265
+ }), /*#__PURE__*/_jsx(Animated.View, {
266
+ pointerEvents: "none",
267
+ style: [StyleSheet.absoluteFill, styles.dim, dimStyle]
268
+ })]
269
+ })
270
+ })
271
+ });
272
+ }
273
+ const styles = StyleSheet.create({
274
+ sheet: {
275
+ position: 'absolute',
276
+ left: 0,
277
+ right: 0,
278
+ top: 0,
279
+ backgroundColor: '#ffffff',
280
+ borderTopLeftRadius: 24,
281
+ borderTopRightRadius: 24,
282
+ overflow: 'hidden',
283
+ transformOrigin: 'top center'
284
+ },
285
+ handleRow: {
286
+ height: HANDLE_HEIGHT,
287
+ alignItems: 'center',
288
+ justifyContent: 'center'
289
+ },
290
+ handle: {
291
+ width: 36,
292
+ height: 5,
293
+ borderRadius: 3,
294
+ backgroundColor: 'rgba(0,0,0,0.2)'
295
+ },
296
+ noHandle: {
297
+ height: NO_HANDLE_HEIGHT
298
+ },
299
+ dim: {
300
+ backgroundColor: '#000'
301
+ }
302
+ });
303
+ //# sourceMappingURL=Sheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","StyleSheet","View","GestureDetector","useNativeGesture","usePanGesture","Animated","Extrapolation","ReduceMotion","cancelAnimation","interpolate","runOnJS","useAnimatedStyle","useSharedValue","withSpring","SheetInstanceContext","pickSnapTarget","resolveSnapHeights","rubberBand","jsx","_jsx","jsxs","_jsxs","HANDLE_HEIGHT","NO_HANDLE_HEIGHT","OVERSHOOT","ACTIVATE_DISTANCE","OPEN_SPRING","damping","stiffness","mass","reduceMotion","System","CLOSE_SPRING","overshootClamping","Sheet","entry","index","depth","isTop","containerHeight","topInset","bottomInset","keyboardHeight","onClosed","requestDismiss","options","handleHeight","handle","needsMeasure","snapPoints","includes","contentHeight","setContentHeight","measured","setMeasured","maxHeight","Math","max","snapHeights","maxSnapHeight","length","closedY","snapYs","map","h","lowestY","topY","ready","isOpen","status","y","depthSv","dragStartY","moved","dragging","scrollY","hasScroll","snapYsSv","topYSv","lowestYSv","closedYSv","dismissibleSv","dismissible","currentSnap","initialSnap","opened","closing","value","onSnapRef","onSnap","current","notifySnap","snapIndex","initial","finished","min","finish","id","onDismiss","scrollGesture","pan","enabled","activeOffsetY","simultaneousWith","onBegin","onUpdate","e","translationY","next","abs","onDeactivate","target","velocityY","velocity","onFinalize","keyboardPadding","keyboardBehavior","stackOffset","stackScale","sheetStyle","d","progress","CLAMP","lift","base","height","opacity","transform","translateY","scale","pow","dimStyle","onContentLayout","round","nativeEvent","layout","prev","contentStyle","renderContext","dismiss","instance","Provider","children","gesture","style","styles","sheet","paddingBottom","accessibilityViewIsModal","importantForAccessibility","handleRow","noHandle","onLayout","undefined","render","pointerEvents","absoluteFill","dim","create","position","left","right","top","backgroundColor","borderTopLeftRadius","borderTopRightRadius","overflow","transformOrigin","alignItems","justifyContent","width","borderRadius"],"sourceRoot":"../../src","sources":["Sheet.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzE,SACEC,UAAU,EACVC,IAAI,QAGC,cAAc;AACrB,SACEC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,QACR,8BAA8B;AACrC,OAAOC,QAAQ,IACbC,aAAa,EACbC,YAAY,EACZC,eAAe,EACfC,WAAW,EACXC,OAAO,EACPC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QAEL,yBAAyB;AAChC,SAASC,oBAAoB,QAA4B,cAAW;AAEpE,SAASC,cAAc,EAAEC,kBAAkB,EAAEC,UAAU,QAAQ,iBAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE9E,OAAO,MAAMC,aAAa,GAAG,EAAE;AAC/B,MAAMC,gBAAgB,GAAG,CAAC;AAC1B;AACA,MAAMC,SAAS,G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ACNC,eAAe,EAAE,SAAS;IAC1BC,mBAAmB,EAAE,EAAE;IACvBC,oBAAoB,EAAE,EAAE;IACxBC,QAAQ,EAAE,QAAQ;IAClBC,eAAe,EAAE;EACnB,CAAC;EACDjB,SAAS,EAAE;IACTzB,MAAM,EAAEvG,aAAa;IACrBkJ,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACD1H,MAAM,EAAE;IACN2H,KAAK,EAAE,EAAE;IACT7C,MAAM,EAAE,CAAC;IACT8C,YAAY,EAAE,CAAC;IACfR,eAAe,EAAE;EACnB,CAAC;EACDZ,QAAQ,EAAE;IAAE1B,MAAM,EAAEtG;EAAiB,CAAC;EACtCsI,GAAG,EAAE;IAAEM,eAAe,EAAE;EAAO;AACjC,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
4
+ import { BackHandler, Keyboard, Platform, StyleSheet, View } from 'react-native';
5
+ import { Easing, ReduceMotion, useSharedValue, withTiming } from 'react-native-reanimated';
6
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
7
+ import { Backdrop } from "./Backdrop.js";
8
+ import { ActionsContext, RemoveContext, StackContext } from "./context.js";
9
+ import { Sheet } from "./Sheet.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const TOP_GAP = 8;
12
+ export function SheetHost() {
13
+ const entries = useContext(StackContext);
14
+ const actions = useContext(ActionsContext);
15
+ const remove = useContext(RemoveContext);
16
+ const insets = useSafeAreaInsets();
17
+ const [containerHeight, setContainerHeight] = useState(0);
18
+ const keyboardHeight = useSharedValue(0);
19
+ const backdropOpacity = useSharedValue(0);
20
+ const open = useMemo(() => entries.filter(e => e.status === 'open'), [entries]);
21
+ const top = open[open.length - 1];
22
+ const dismiss = useCallback(id => {
23
+ actions?.dismiss(id);
24
+ }, [actions]);
25
+ useEffect(() => {
26
+ const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
27
+ const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
28
+ const animate = (to, e) => {
29
+ keyboardHeight.value = withTiming(to, {
30
+ duration: e?.duration && e.duration > 0 ? e.duration : 220,
31
+ easing: Easing.out(Easing.cubic),
32
+ reduceMotion: ReduceMotion.System
33
+ });
34
+ };
35
+ const show = Keyboard.addListener(showEvent, e => animate(e.endCoordinates.height, e));
36
+ const hide = Keyboard.addListener(hideEvent, e => animate(0, e));
37
+ return () => {
38
+ show.remove();
39
+ hide.remove();
40
+ };
41
+ }, [keyboardHeight]);
42
+ useEffect(() => {
43
+ backdropOpacity.value = withTiming(top ? top.options.backdropOpacity : 0, {
44
+ duration: 240,
45
+ reduceMotion: ReduceMotion.System
46
+ });
47
+ }, [top, backdropOpacity]);
48
+ useEffect(() => {
49
+ if (!top) {
50
+ return;
51
+ }
52
+ const sub = BackHandler.addEventListener('hardwareBackPress', () => {
53
+ if (top.options.dismissible) {
54
+ dismiss(top.id);
55
+ }
56
+ return true;
57
+ });
58
+ return () => sub.remove();
59
+ }, [top, dismiss]);
60
+ const onLayout = useCallback(e => {
61
+ setContainerHeight(Math.round(e.nativeEvent.layout.height));
62
+ }, []);
63
+ const onBackdropPress = useCallback(() => {
64
+ if (top?.options.dismissible) {
65
+ dismiss(top.id);
66
+ }
67
+ }, [top, dismiss]);
68
+ return /*#__PURE__*/_jsxs(View, {
69
+ style: StyleSheet.absoluteFill,
70
+ pointerEvents: entries.length > 0 ? 'box-none' : 'none',
71
+ onLayout: onLayout,
72
+ children: [/*#__PURE__*/_jsx(Backdrop, {
73
+ opacity: backdropOpacity,
74
+ active: top !== undefined,
75
+ onPress: onBackdropPress
76
+ }), containerHeight > 0 && entries.map((entry, i) => {
77
+ const openIndex = open.indexOf(entry);
78
+ const depth = openIndex === -1 ? 0 : open.length - 1 - openIndex;
79
+ return /*#__PURE__*/_jsx(Sheet, {
80
+ entry: entry,
81
+ index: openIndex === -1 ? i : openIndex,
82
+ depth: depth,
83
+ isTop: entry === top,
84
+ containerHeight: containerHeight,
85
+ topInset: insets.top + TOP_GAP,
86
+ bottomInset: insets.bottom,
87
+ keyboardHeight: keyboardHeight,
88
+ onClosed: remove,
89
+ requestDismiss: dismiss
90
+ }, entry.id);
91
+ })]
92
+ });
93
+ }
94
+ //# sourceMappingURL=SheetHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useContext","useEffect","useMemo","useState","BackHandler","Keyboard","Platform","StyleSheet","View","Easing","ReduceMotion","useSharedValue","withTiming","useSafeAreaInsets","Backdrop","ActionsContext","RemoveContext","StackContext","Sheet","jsx","_jsx","jsxs","_jsxs","TOP_GAP","SheetHost","entries","actions","remove","insets","containerHeight","setContainerHeight","keyboardHeight","backdropOpacity","open","filter","e","status","top","length","dismiss","id","showEvent","OS","hideEvent","animate","to","value","duration","easing","out","cubic","reduceMotion","System","show","addListener","endCoordinates","height","hide","options","sub","addEventListener","dismissible","onLayout","Math","round","nativeEvent","layout","onBackdropPress","style","absoluteFill","pointerEvents","children","opacity","active","undefined","onPress","map","entry","i","openIndex","indexOf","depth","index","isTop","topInset","bottomInset","bottom","onClosed","requestDismiss"],"sourceRoot":"../../src","sources":["SheetHost.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAC7E,SACEC,WAAW,EACXC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,IAAI,QAGC,cAAc;AACrB,SACEC,MAAM,EACNC,YAAY,EACZC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAChC,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,eAAY;AACrC,SAASC,cAAc,EAAEC,aAAa,EAAEC,YAAY,QAAQ,cAAW;AACvE,SAASC,KAAK,QAAQ,YAAS;AAAC,SAAAC,GAAA,IAAAC,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