@oxyhq/bloom 0.30.3 → 0.30.5

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 (80) hide show
  1. package/lib/commonjs/activity-heatmap/ActivityHeatmap.js +2 -37
  2. package/lib/commonjs/activity-heatmap/ActivityHeatmap.js.map +1 -1
  3. package/lib/commonjs/bottom-sheet/BottomSheetBase.js +731 -0
  4. package/lib/commonjs/bottom-sheet/BottomSheetBase.js.map +1 -0
  5. package/lib/commonjs/bottom-sheet/index.js +24 -694
  6. package/lib/commonjs/bottom-sheet/index.js.map +1 -1
  7. package/lib/commonjs/bottom-sheet/index.web.js +64 -0
  8. package/lib/commonjs/bottom-sheet/index.web.js.map +1 -0
  9. package/lib/commonjs/dialog/Dialog.js +2 -2
  10. package/lib/commonjs/dialog/Dialog.js.map +1 -1
  11. package/lib/commonjs/dialog/DialogBottomSheet.js +2 -2
  12. package/lib/commonjs/dialog/DialogBottomSheet.js.map +1 -1
  13. package/lib/commonjs/dialog/SheetShell.js +2 -2
  14. package/lib/commonjs/dialog/SheetShell.js.map +1 -1
  15. package/lib/commonjs/index.js +44 -44
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/index.web.js +66 -66
  18. package/lib/commonjs/index.web.js.map +1 -1
  19. package/lib/commonjs/theme/color-utils.js +65 -0
  20. package/lib/commonjs/theme/color-utils.js.map +1 -0
  21. package/lib/commonjs/theme/index.js +13 -0
  22. package/lib/commonjs/theme/index.js.map +1 -1
  23. package/lib/module/activity-heatmap/ActivityHeatmap.js +1 -36
  24. package/lib/module/activity-heatmap/ActivityHeatmap.js.map +1 -1
  25. package/lib/module/bottom-sheet/BottomSheetBase.js +728 -0
  26. package/lib/module/bottom-sheet/BottomSheetBase.js.map +1 -0
  27. package/lib/module/bottom-sheet/index.js +27 -696
  28. package/lib/module/bottom-sheet/index.js.map +1 -1
  29. package/lib/module/bottom-sheet/index.web.js +63 -0
  30. package/lib/module/bottom-sheet/index.web.js.map +1 -0
  31. package/lib/module/dialog/Dialog.js +1 -1
  32. package/lib/module/dialog/Dialog.js.map +1 -1
  33. package/lib/module/dialog/DialogBottomSheet.js +1 -1
  34. package/lib/module/dialog/DialogBottomSheet.js.map +1 -1
  35. package/lib/module/dialog/SheetShell.js +1 -1
  36. package/lib/module/dialog/SheetShell.js.map +1 -1
  37. package/lib/module/index.js +1 -1
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/index.web.js +1 -1
  40. package/lib/module/index.web.js.map +1 -1
  41. package/lib/module/theme/color-utils.js +60 -0
  42. package/lib/module/theme/color-utils.js.map +1 -0
  43. package/lib/module/theme/index.js +1 -0
  44. package/lib/module/theme/index.js.map +1 -1
  45. package/lib/typescript/commonjs/activity-heatmap/ActivityHeatmap.d.ts.map +1 -1
  46. package/lib/typescript/commonjs/bottom-sheet/BottomSheetBase.d.ts +127 -0
  47. package/lib/typescript/commonjs/bottom-sheet/BottomSheetBase.d.ts.map +1 -0
  48. package/lib/typescript/commonjs/bottom-sheet/index.d.ts +2 -90
  49. package/lib/typescript/commonjs/bottom-sheet/index.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/bottom-sheet/index.web.d.ts +7 -0
  51. package/lib/typescript/commonjs/bottom-sheet/index.web.d.ts.map +1 -0
  52. package/lib/typescript/commonjs/index.web.d.ts +2 -2
  53. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/theme/color-utils.d.ts +28 -0
  55. package/lib/typescript/commonjs/theme/color-utils.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/theme/index.d.ts +2 -0
  57. package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
  58. package/lib/typescript/module/activity-heatmap/ActivityHeatmap.d.ts.map +1 -1
  59. package/lib/typescript/module/bottom-sheet/BottomSheetBase.d.ts +127 -0
  60. package/lib/typescript/module/bottom-sheet/BottomSheetBase.d.ts.map +1 -0
  61. package/lib/typescript/module/bottom-sheet/index.d.ts +2 -90
  62. package/lib/typescript/module/bottom-sheet/index.d.ts.map +1 -1
  63. package/lib/typescript/module/bottom-sheet/index.web.d.ts +7 -0
  64. package/lib/typescript/module/bottom-sheet/index.web.d.ts.map +1 -0
  65. package/lib/typescript/module/index.web.d.ts +2 -2
  66. package/lib/typescript/module/index.web.d.ts.map +1 -1
  67. package/lib/typescript/module/theme/color-utils.d.ts +28 -0
  68. package/lib/typescript/module/theme/color-utils.d.ts.map +1 -0
  69. package/lib/typescript/module/theme/index.d.ts +2 -0
  70. package/lib/typescript/module/theme/index.d.ts.map +1 -1
  71. package/package.json +6 -1
  72. package/src/__tests__/BottomSheetWebFork.test.ts +66 -0
  73. package/src/activity-heatmap/ActivityHeatmap.tsx +1 -29
  74. package/src/bottom-sheet/BottomSheetBase.tsx +853 -0
  75. package/src/bottom-sheet/index.tsx +26 -821
  76. package/src/bottom-sheet/index.web.tsx +66 -0
  77. package/src/index.web.ts +2 -2
  78. package/src/theme/__tests__/color-utils.test.ts +40 -0
  79. package/src/theme/color-utils.ts +54 -0
  80. package/src/theme/index.ts +2 -0
@@ -0,0 +1,731 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BottomSheetBase = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeGestureHandler = require("react-native-gesture-handler");
10
+ var _zIndex = require("../styles/z-index.js");
11
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
12
+ var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
13
+ var _useTheme = require("../theme/use-theme.js");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ /** Hook that returns current screen dimensions and updates on rotation/resize. */function useScreenDimensions() {
17
+ const [dimensions, setDimensions] = (0, _react.useState)(() => _reactNative.Dimensions.get('window'));
18
+ (0, _react.useEffect)(() => {
19
+ const subscription = _reactNative.Dimensions.addEventListener('change', ({
20
+ window
21
+ }) => {
22
+ setDimensions(window);
23
+ });
24
+ return () => subscription.remove();
25
+ }, []);
26
+ return dimensions;
27
+ }
28
+ const SPRING_CONFIG = {
29
+ damping: 25,
30
+ stiffness: 300,
31
+ mass: 0.8
32
+ };
33
+
34
+ /**
35
+ * Props consumed by a platform Shell — the outermost wrapper that hosts the
36
+ * sheet body in a full-screen overlay. Native wraps it in RN's `<Modal>` +
37
+ * `<KeyboardProvider>` + `<GestureHandlerRootView>`; web wraps it in bloom's
38
+ * stable DOM `<Portal>` + a fixed `<GestureHandlerRootView>`. Splitting the
39
+ * shell is what lets web avoid RN-Web's `<Modal>`/`ModalPortal`, whose host
40
+ * node is orphaned under React 19 concurrent/StrictMode so the sheet mounts
41
+ * but never paints.
42
+ */
43
+
44
+ /**
45
+ * Platform-agnostic bottom-sheet core: all gesture, animation, scroll, and
46
+ * dismissal logic lives here so native and web share ONE implementation. The
47
+ * only thing that differs per platform is the `Shell` (see
48
+ * `BottomSheetShellProps`) — injected by `index.tsx` (native) and
49
+ * `index.web.tsx` (web). This module imports nothing platform-specific
50
+ * (no RN `<Modal>`, no `react-native-keyboard-controller`) so it is safe to
51
+ * bundle on web.
52
+ */
53
+
54
+ const BottomSheetBase = exports.BottomSheetBase = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
55
+ const {
56
+ Shell,
57
+ children,
58
+ onDismiss,
59
+ enablePanDownToClose = true,
60
+ backgroundComponent,
61
+ backdropComponent,
62
+ style,
63
+ enableHandlePanningGesture = true,
64
+ onDismissAttempt,
65
+ detached = false,
66
+ showHandle = true,
67
+ backdropOpacity = 0.5,
68
+ scrollable = true,
69
+ manualActivation = false,
70
+ dynamicBackdrop = false,
71
+ handleComponent
72
+ } = props;
73
+ const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
74
+ const theme = (0, _useTheme.useTheme)();
75
+ const {
76
+ colors
77
+ } = theme;
78
+ const {
79
+ height: screenHeight
80
+ } = useScreenDimensions();
81
+ const [visible, setVisible] = (0, _react.useState)(false);
82
+ const [rendered, setRendered] = (0, _react.useState)(false); // keep mounted for exit animation
83
+ const closeTimeoutRef = (0, _react.useRef)(null);
84
+ const hasClosedRef = (0, _react.useRef)(false);
85
+ const scrollViewRef = (0, _react.useRef)(null);
86
+ /**
87
+ * Monotonically increasing counter that identifies "the current close
88
+ * attempt". Bumped every time the sheet re-opens (`present()`), so any
89
+ * in-flight `withTiming` completion callback or fallback timer from a
90
+ * PREVIOUS close cycle becomes a no-op. Without this guard, a stale
91
+ * `runOnJS(finishClose)` from an aborted close would fire `onDismiss`
92
+ * and unmount the sheet immediately after the user opens it again,
93
+ * causing "tap to open does nothing" reports in production.
94
+ */
95
+ const closeGenerationRef = (0, _react.useRef)(0);
96
+ const screenHeightSV = (0, _reactNativeReanimated.useSharedValue)(screenHeight);
97
+ // Keep shared value in sync when screen dimensions change (rotation/resize)
98
+ (0, _react.useEffect)(() => {
99
+ screenHeightSV.value = screenHeight;
100
+ }, [screenHeight, screenHeightSV]);
101
+ const translateY = (0, _reactNativeReanimated.useSharedValue)(screenHeight);
102
+ const opacity = (0, _reactNativeReanimated.useSharedValue)(0);
103
+ const scrollOffsetY = (0, _reactNativeReanimated.useSharedValue)(0);
104
+ const isScrollAtTop = (0, _reactNativeReanimated.useSharedValue)(true);
105
+ const allowPanClose = (0, _reactNativeReanimated.useSharedValue)(true);
106
+ // Live keyboard height. Written by the native shell's keyboard tracker via
107
+ // this shared value; on web it stays 0 (the browser owns keyboard layout).
108
+ const keyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
109
+ // Stores the sheet's `translateY` captured at the moment a pan gesture
110
+ // begins, so `onUpdate` can offset from the starting position. This MUST
111
+ // be a primitive shared value, not an object-valued one. Under
112
+ // react-native-worklets 0.8.x (Reanimated 4), assigning a fresh object
113
+ // literal to an object-valued shared value's `.value` inside a worklet
114
+ // freezes the object (`freezeObjectInDev`) and routes the mutation through
115
+ // the serializer's listener machinery — which then tries to call the
116
+ // non-worklet `removeListener` synchronously on the UI thread and crashes
117
+ // ("Tried to synchronously call a non-worklet function `removeListener`").
118
+ // A scalar shared value sidesteps all object serialization.
119
+ const contextY = (0, _reactNativeReanimated.useSharedValue)(0);
120
+ // Mirror of `closeGenerationRef` for worklet access. Bumped from the JS
121
+ // thread in lockstep with the ref so gesture worklets always see the
122
+ // current generation when they snapshot it on `onEnd`.
123
+ const closeGeneration = (0, _reactNativeReanimated.useSharedValue)(0);
124
+ // Used by `manualActivation` body pan to track the touch's initial Y so
125
+ // it can compute downward distance for the activation decision.
126
+ const touchStartY = (0, _reactNativeReanimated.useSharedValue)(0);
127
+
128
+ // Refs used to mark the handle pan and the body pan as mutually
129
+ // simultaneous (manualActivation mode only). Without this RNGH treats them
130
+ // as racing gestures and a touch that begins in the handle area could be
131
+ // claimed by whichever recognizer activates first — leading to
132
+ // inconsistent drag start.
133
+ const bodyPanRef = (0, _react.useRef)(undefined);
134
+ const handlePanRef = (0, _react.useRef)(undefined);
135
+
136
+ // Dismiss callbacks
137
+ const safeClose = (0, _react.useCallback)(() => {
138
+ if (onDismissAttempt?.()) {
139
+ onDismiss?.();
140
+ } else if (!onDismissAttempt) {
141
+ onDismiss?.();
142
+ }
143
+ }, [onDismissAttempt, onDismiss]);
144
+
145
+ // Mirror `safeClose` and `rendered` into refs so the unmount cleanup can
146
+ // fire the latest dismiss callback when needed, without re-binding the
147
+ // cleanup effect on every render.
148
+ const safeCloseRef = (0, _react.useRef)(safeClose);
149
+ (0, _react.useEffect)(() => {
150
+ safeCloseRef.current = safeClose;
151
+ }, [safeClose]);
152
+ const renderedRef = (0, _react.useRef)(rendered);
153
+ (0, _react.useEffect)(() => {
154
+ renderedRef.current = rendered;
155
+ }, [rendered]);
156
+
157
+ /**
158
+ * Commit a close. Two guards prevent stale callbacks from firing:
159
+ * 1. `hasClosedRef` — protects against the fallback timer AND the
160
+ * animation callback both racing to call us within a single close
161
+ * cycle.
162
+ * 2. `generation` — protects against a callback from a PREVIOUS close
163
+ * cycle firing AFTER the user reopened. If the live generation has
164
+ * advanced past the one captured when the close started, this
165
+ * callback is from a cycle that the user has implicitly cancelled
166
+ * by reopening — silently drop it.
167
+ */
168
+ const finishClose = (0, _react.useCallback)(generation => {
169
+ if (closeGenerationRef.current !== generation) return;
170
+ if (hasClosedRef.current) return;
171
+ hasClosedRef.current = true;
172
+ safeClose();
173
+ setRendered(false);
174
+ }, [safeClose]);
175
+ (0, _react.useEffect)(() => {
176
+ if (visible) {
177
+ if (closeTimeoutRef.current) {
178
+ clearTimeout(closeTimeoutRef.current);
179
+ closeTimeoutRef.current = null;
180
+ }
181
+ hasClosedRef.current = false;
182
+ // Bump generation: any pending close-completion callback from a
183
+ // prior cycle (animation or fallback timer) will now no-op when
184
+ // it eventually fires, because its captured generation is stale.
185
+ closeGenerationRef.current += 1;
186
+ closeGeneration.value = closeGenerationRef.current;
187
+ opacity.value = (0, _reactNativeReanimated.withTiming)(1, {
188
+ duration: 250
189
+ });
190
+ translateY.value = (0, _reactNativeReanimated.withSpring)(0, SPRING_CONFIG);
191
+ } else if (rendered) {
192
+ // Capture the generation for THIS close cycle so the animation
193
+ // callback (running on the UI thread, scheduled back to JS) and
194
+ // the fallback timer agree on which cycle they belong to.
195
+ const generation = closeGenerationRef.current;
196
+ opacity.value = (0, _reactNativeReanimated.withTiming)(0, {
197
+ duration: 250
198
+ }, finished => {
199
+ if (finished) {
200
+ (0, _reactNativeReanimated.runOnJS)(finishClose)(generation);
201
+ }
202
+ });
203
+ translateY.value = (0, _reactNativeReanimated.withSpring)(screenHeight, {
204
+ ...SPRING_CONFIG,
205
+ stiffness: 250
206
+ });
207
+
208
+ // Fallback timer to ensure close completes (especially on web
209
+ // where reanimated callbacks occasionally drop on tab blur).
210
+ if (closeTimeoutRef.current) {
211
+ clearTimeout(closeTimeoutRef.current);
212
+ }
213
+ closeTimeoutRef.current = setTimeout(() => {
214
+ finishClose(generation);
215
+ closeTimeoutRef.current = null;
216
+ }, 300);
217
+ }
218
+ }, [visible, rendered, finishClose, screenHeight, closeGeneration, opacity, translateY]);
219
+
220
+ // On unmount: ensure pending close callbacks (e.g. consumer's `onDismiss`)
221
+ // still fire if the BS is yanked mid-animation by a parent re-render.
222
+ // Without this, `Dialog`'s `handleDismiss` never runs and queued
223
+ // callbacks (post-close handlers) are silently lost.
224
+ // Only fires when the sheet was actually rendered (open or closing) to
225
+ // avoid spuriously calling onDismiss on bare unmount of a never-opened
226
+ // sheet. Refs are read inside the cleanup, so latest values are captured.
227
+ (0, _react.useEffect)(() => () => {
228
+ if (closeTimeoutRef.current) {
229
+ clearTimeout(closeTimeoutRef.current);
230
+ closeTimeoutRef.current = null;
231
+ }
232
+ if (renderedRef.current && !hasClosedRef.current) {
233
+ hasClosedRef.current = true;
234
+ safeCloseRef.current();
235
+ }
236
+ }, []);
237
+
238
+ // Apply web scrollbar styles when colors change; clean up on unmount
239
+ (0, _react.useEffect)(() => {
240
+ if (_reactNative.Platform.OS === 'web') {
241
+ createWebScrollbarStyle(colors.border);
242
+ }
243
+ return () => {
244
+ removeWebScrollbarStyle();
245
+ };
246
+ }, [colors.border]);
247
+ const present = (0, _react.useCallback)(() => {
248
+ setRendered(true);
249
+ setVisible(true);
250
+ }, []);
251
+ const dismiss = (0, _react.useCallback)(() => {
252
+ setVisible(false);
253
+ }, []);
254
+ const scrollTo = (0, _react.useCallback)((y, animated = true) => {
255
+ scrollViewRef.current?.scrollTo({
256
+ y,
257
+ animated
258
+ });
259
+ }, []);
260
+ (0, _react.useImperativeHandle)(ref, () => ({
261
+ present,
262
+ dismiss,
263
+ close: dismiss,
264
+ expand: present,
265
+ collapse: dismiss,
266
+ scrollTo
267
+ }), [present, dismiss, scrollTo]);
268
+ const nativeGesture = (0, _react.useMemo)(() => _reactNativeGestureHandler.Gesture.Native(), []);
269
+
270
+ // Body pan — two strategies, switched by `manualActivation`.
271
+ //
272
+ // (1) Legacy mode (`manualActivation: false`, the bloom 0.3.x default):
273
+ // Pan is always active. We snapshot the scroll offset at `onStart`
274
+ // and gate movement on `scrollOffsetY <= 8` during the gesture.
275
+ // This is what current bloom consumers expect.
276
+ //
277
+ // (2) gorhom-style mode (`manualActivation: true`):
278
+ // Pan uses `manualActivation(true)` and only flips to active when
279
+ // the inner ScrollView is at the top AND the user has moved their
280
+ // finger downward > 8dp. In every other case it fails, so the
281
+ // ScrollView keeps full ownership of the touch. This is the only
282
+ // RNGH 2.x pattern that does not steal vertical events from the
283
+ // inner scroller on Android. Required for FileManagement /
284
+ // PhotoPicker style sheets.
285
+ const panGesture = (0, _react.useMemo)(() => {
286
+ if (manualActivation) {
287
+ return _reactNativeGestureHandler.Gesture.Pan().enabled(enablePanDownToClose).withRef(bodyPanRef).manualActivation(true).simultaneousWithExternalGesture(scrollViewRef, handlePanRef).onTouchesDown(e => {
288
+ 'worklet';
289
+
290
+ const t = e.changedTouches[0];
291
+ if (t) touchStartY.value = t.absoluteY;
292
+ contextY.value = translateY.value;
293
+ }).onTouchesMove((e, state) => {
294
+ 'worklet';
295
+
296
+ const t = e.changedTouches[0];
297
+ if (!t) return;
298
+ const dy = t.absoluteY - touchStartY.value;
299
+ const atTop = scrollOffsetY.value <= 4;
300
+ // Activate only when (at scroll top) AND (finger has moved
301
+ // downward by > 8dp). Any other motion: fail so the
302
+ // ScrollView claims the gesture.
303
+ if (atTop && dy > 8) {
304
+ state.activate();
305
+ } else if (dy < -4 || !atTop) {
306
+ state.fail();
307
+ }
308
+ }).onUpdate(event => {
309
+ 'worklet';
310
+
311
+ if (event.translationY < 0) return;
312
+ const newTranslateY = contextY.value + event.translationY;
313
+ if (newTranslateY >= 0) {
314
+ translateY.value = newTranslateY;
315
+ }
316
+ }).onEnd(event => {
317
+ 'worklet';
318
+
319
+ const velocity = event.velocityY;
320
+ const distance = translateY.value;
321
+ const closeThreshold = Math.max(140, screenHeightSV.value * 0.25);
322
+ const fastSwipeThreshold = 900;
323
+ const shouldClose = velocity > fastSwipeThreshold || distance > closeThreshold && velocity > -300;
324
+ if (shouldClose) {
325
+ // Snapshot the generation on the UI thread at the
326
+ // moment the close gesture commits. The completion
327
+ // callback only fires `finishClose` if no reopen
328
+ // bumped the generation in between.
329
+ const generation = closeGeneration.value;
330
+ translateY.value = (0, _reactNativeReanimated.withSpring)(screenHeightSV.value, {
331
+ ...SPRING_CONFIG,
332
+ velocity
333
+ });
334
+ opacity.value = (0, _reactNativeReanimated.withTiming)(0, {
335
+ duration: 250
336
+ }, finished => {
337
+ if (finished) (0, _reactNativeReanimated.runOnJS)(finishClose)(generation);
338
+ });
339
+ } else {
340
+ translateY.value = (0, _reactNativeReanimated.withSpring)(0, {
341
+ ...SPRING_CONFIG,
342
+ velocity
343
+ });
344
+ }
345
+ });
346
+ }
347
+
348
+ // Legacy always-active pan (bloom 0.3.x behaviour).
349
+ return _reactNativeGestureHandler.Gesture.Pan().enabled(enablePanDownToClose).simultaneousWithExternalGesture(nativeGesture).onStart(() => {
350
+ 'worklet';
351
+
352
+ contextY.value = translateY.value;
353
+ allowPanClose.value = scrollOffsetY.value <= 8;
354
+ }).onUpdate(event => {
355
+ 'worklet';
356
+
357
+ if (!allowPanClose.value) {
358
+ return;
359
+ }
360
+ const newTranslateY = contextY.value + event.translationY;
361
+ // If user is scrolling down while content isn't at (or near) the top, let ScrollView handle it
362
+ const atTopOrNearTop = scrollOffsetY.value <= 8; // slightly larger tolerance for smoother handoff
363
+ if (event.translationY > 0 && !atTopOrNearTop) {
364
+ return;
365
+ }
366
+ if (newTranslateY >= 0) {
367
+ translateY.value = newTranslateY;
368
+ } else if (detached) {
369
+ // Only allow overdrag (pulling up beyond top) when detached
370
+ translateY.value = newTranslateY * 0.3;
371
+ } else {
372
+ // In normal mode, prevent overdrag - clamp to 0
373
+ translateY.value = 0;
374
+ }
375
+ }).onEnd(event => {
376
+ 'worklet';
377
+
378
+ if (!allowPanClose.value) {
379
+ return;
380
+ }
381
+ const velocity = event.velocityY;
382
+ const distance = translateY.value;
383
+ // Require a deeper pull to close (more like native bottom sheets)
384
+ const closeThreshold = Math.max(140, screenHeightSV.value * 0.25);
385
+ const fastSwipeThreshold = 900;
386
+ const shouldClose = velocity > fastSwipeThreshold || distance > closeThreshold && velocity > -300;
387
+ if (shouldClose) {
388
+ const generation = closeGeneration.value;
389
+ translateY.value = (0, _reactNativeReanimated.withSpring)(screenHeightSV.value, {
390
+ ...SPRING_CONFIG,
391
+ velocity: velocity
392
+ });
393
+ opacity.value = (0, _reactNativeReanimated.withTiming)(0, {
394
+ duration: 250
395
+ }, finished => {
396
+ if (finished) {
397
+ (0, _reactNativeReanimated.runOnJS)(finishClose)(generation);
398
+ }
399
+ });
400
+ } else {
401
+ translateY.value = (0, _reactNativeReanimated.withSpring)(0, {
402
+ ...SPRING_CONFIG,
403
+ velocity: velocity
404
+ });
405
+ }
406
+ });
407
+ // Shared values are stable refs; the listed deps are the only JS-side
408
+ // values that change the gesture's behavior. `finishClose` is stable
409
+ // (useCallback with stable deps).
410
+ // eslint-disable-next-line react-hooks/exhaustive-deps
411
+ }, [enablePanDownToClose, detached, manualActivation, nativeGesture, finishClose]);
412
+
413
+ // Dedicated handle pan — only built in `manualActivation` mode. Always
414
+ // active so users can drag the handle even while content is mid-scroll.
415
+ // In legacy mode the body pan already wraps the whole sheet (handle
416
+ // included), so no separate gesture is needed.
417
+ const handlePanGesture = (0, _react.useMemo)(() => {
418
+ if (!manualActivation) return undefined;
419
+ return _reactNativeGestureHandler.Gesture.Pan().enabled(enablePanDownToClose && enableHandlePanningGesture).withRef(handlePanRef).simultaneousWithExternalGesture(bodyPanRef).activeOffsetY([-8, 8]).onStart(() => {
420
+ 'worklet';
421
+
422
+ contextY.value = translateY.value;
423
+ }).onUpdate(event => {
424
+ 'worklet';
425
+
426
+ const newTranslateY = contextY.value + event.translationY;
427
+ if (newTranslateY >= 0) {
428
+ translateY.value = newTranslateY;
429
+ } else if (detached) {
430
+ translateY.value = newTranslateY * 0.3;
431
+ } else {
432
+ translateY.value = 0;
433
+ }
434
+ }).onEnd(event => {
435
+ 'worklet';
436
+
437
+ const velocity = event.velocityY;
438
+ const distance = translateY.value;
439
+ const closeThreshold = Math.max(140, screenHeightSV.value * 0.25);
440
+ const fastSwipeThreshold = 900;
441
+ const shouldClose = velocity > fastSwipeThreshold || distance > closeThreshold && velocity > -300;
442
+ if (shouldClose) {
443
+ const generation = closeGeneration.value;
444
+ translateY.value = (0, _reactNativeReanimated.withSpring)(screenHeightSV.value, {
445
+ ...SPRING_CONFIG,
446
+ velocity
447
+ });
448
+ opacity.value = (0, _reactNativeReanimated.withTiming)(0, {
449
+ duration: 250
450
+ }, finished => {
451
+ if (finished) (0, _reactNativeReanimated.runOnJS)(finishClose)(generation);
452
+ });
453
+ } else {
454
+ translateY.value = (0, _reactNativeReanimated.withSpring)(0, {
455
+ ...SPRING_CONFIG,
456
+ velocity
457
+ });
458
+ }
459
+ });
460
+ // eslint-disable-next-line react-hooks/exhaustive-deps
461
+ }, [manualActivation, enablePanDownToClose, enableHandlePanningGesture, detached, finishClose]);
462
+
463
+ // `opacity.value` drives the fade in/out (0 -> 1). `backdropOpacity` is the
464
+ // final dim level once fully visible. We multiply so the consumer-provided
465
+ // dim opacity applies smoothly across the animation. When
466
+ // `dynamicBackdrop` is enabled, the dim also fades proportionally with
467
+ // drag distance (iOS Photos style).
468
+ const backdropStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
469
+ const dragFactor = dynamicBackdrop ? (0, _reactNativeReanimated.interpolate)(translateY.value, [0, screenHeightSV.value * 0.4], [1, 0.3], 'clamp') : 1;
470
+ return {
471
+ opacity: opacity.value * backdropOpacity * dragFactor
472
+ };
473
+ }, [backdropOpacity, dynamicBackdrop]);
474
+ const sheetStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
475
+ const scale = (0, _reactNativeReanimated.interpolate)(translateY.value, [0, screenHeightSV.value], [1, 0.95]);
476
+ return {
477
+ transform: [{
478
+ translateY: translateY.value - keyboardHeight.value
479
+ }, {
480
+ scale
481
+ }]
482
+ };
483
+ }, []);
484
+ const sheetHeightStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
485
+ maxHeight: screenHeightSV.value - keyboardHeight.value - insets.top - (detached ? insets.bottom + 16 : 0)
486
+ }), [insets.top, insets.bottom, detached]);
487
+ const sheetMarginStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
488
+ // Only add margin when detached, otherwise extend behind safe area
489
+ if (detached) {
490
+ return {
491
+ marginBottom: keyboardHeight.value > 0 ? 16 : insets.bottom + 16
492
+ };
493
+ }
494
+ return {
495
+ marginBottom: 0
496
+ };
497
+ }, [insets.bottom, detached]);
498
+ const handleBackdropPress = (0, _react.useCallback)(() => {
499
+ // Always animate close on backdrop press
500
+ if (onDismissAttempt && !onDismissAttempt()) {
501
+ return;
502
+ }
503
+ dismiss();
504
+ }, [onDismissAttempt, dismiss]);
505
+ const scrollHandler = (0, _reactNativeReanimated.useAnimatedScrollHandler)({
506
+ onScroll: event => {
507
+ scrollOffsetY.value = event.contentOffset.y;
508
+ isScrollAtTop.value = event.contentOffset.y <= 0;
509
+ }
510
+ }, []);
511
+ const dynamicStyles = (0, _react.useMemo)(() => {
512
+ return _reactNative.StyleSheet.create({
513
+ handle: {
514
+ ...styles.handle,
515
+ backgroundColor: theme.isDark ? '#444' : '#C7C7CC'
516
+ },
517
+ sheet: {
518
+ ...styles.sheet,
519
+ backgroundColor: colors.background,
520
+ ...(detached ? styles.sheetDetached : styles.sheetNormal)
521
+ },
522
+ scrollContent: {
523
+ ...styles.scrollContent
524
+ // In normal mode, don't add padding here - screens handle their own padding
525
+ // The sheet extends behind safe area, and screens add padding as needed
526
+ }
527
+ });
528
+ }, [colors.background, theme.isDark, detached]);
529
+
530
+ // Publish the sheet's keyboard shared value to the shell so the native
531
+ // shell can drive it from inside its own <KeyboardProvider>. Kept stable
532
+ // (shared values are stable refs) so the shell never re-mounts for this.
533
+ if (!rendered) return null;
534
+
535
+ // Default handle render — used when `handleComponent` is not provided.
536
+ const renderDefaultHandle = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
537
+ style: dynamicStyles.handle
538
+ });
539
+ const handleNode = showHandle ? handleComponent ? handleComponent() : renderDefaultHandle() : null;
540
+
541
+ // In `manualActivation` mode the handle gets its own gesture detector
542
+ // sitting in a dedicated absolutely-positioned hit area at the top of the
543
+ // sheet. In legacy mode the handle is rendered inline as a decorative
544
+ // overlay (the body pan covers the entire sheet, handle included).
545
+ const handleSlot = handleNode && manualActivation && handlePanGesture ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
546
+ gesture: handlePanGesture,
547
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
548
+ style: styles.handleHitArea,
549
+ accessible: true,
550
+ accessibilityRole: "adjustable",
551
+ children: handleNode
552
+ })
553
+ }) : handleNode;
554
+
555
+ // Inner content: scrollable wraps in Animated.ScrollView, non-scrollable
556
+ // renders children directly. In legacy mode the scrollview is also
557
+ // wrapped in the `nativeGesture` detector for scroll/pan coordination.
558
+ const scrollViewNode = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.ScrollView, {
559
+ ref: scrollViewRef,
560
+ style: [styles.scrollView, _reactNative.Platform.OS === 'web' && {
561
+ scrollbarWidth: 'thin',
562
+ scrollbarColor: `${colors.border} transparent`
563
+ }],
564
+ contentContainerStyle: dynamicStyles.scrollContent,
565
+ showsVerticalScrollIndicator: false,
566
+ keyboardShouldPersistTaps: "handled",
567
+ onScroll: scrollHandler,
568
+ scrollEventThrottle: 16,
569
+ ...(_reactNative.Platform.OS === 'web' ? {
570
+ className: 'bottom-sheet-scrollview'
571
+ } : undefined),
572
+ onLayout: () => {
573
+ if (_reactNative.Platform.OS === 'web') {
574
+ createWebScrollbarStyle(colors.border);
575
+ }
576
+ },
577
+ children: children
578
+ });
579
+ const bodyContent = scrollable ? manualActivation
580
+ // In manualActivation mode the scroll view is referenced by the
581
+ // pan's simultaneous list directly; no wrapping native gesture.
582
+ ? scrollViewNode
583
+ // Legacy mode: native gesture wraps the scroll view to coordinate
584
+ // with the always-active body pan.
585
+ : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
586
+ gesture: nativeGesture,
587
+ children: scrollViewNode
588
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
589
+ style: styles.nonScrollableContent,
590
+ children: children
591
+ });
592
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Shell, {
593
+ visible: rendered,
594
+ onRequestClose: dismiss,
595
+ keyboardHeight: keyboardHeight,
596
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
597
+ style: _reactNative.StyleSheet.absoluteFill,
598
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
599
+ style: [styles.backdrop, backdropStyle],
600
+ children: backdropComponent ? backdropComponent({
601
+ onPress: handleBackdropPress
602
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
603
+ style: styles.backdropTouchable,
604
+ onPress: handleBackdropPress,
605
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
606
+ style: _reactNative.StyleSheet.absoluteFill
607
+ })
608
+ })
609
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
610
+ gesture: panGesture,
611
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeReanimated.default.View, {
612
+ style: [dynamicStyles.sheet, sheetMarginStyle, sheetStyle, sheetHeightStyle, style],
613
+ children: [backgroundComponent?.({
614
+ style: styles.background
615
+ }), handleSlot, bodyContent]
616
+ })
617
+ })]
618
+ })
619
+ });
620
+ });
621
+ BottomSheetBase.displayName = 'BottomSheetBase';
622
+ const styles = _reactNative.StyleSheet.create({
623
+ backdrop: {
624
+ // Color is solid black; the dim level is driven by `backdropOpacity` via
625
+ // the animated `opacity` style on the wrapping <Animated.View>.
626
+ flex: 1,
627
+ backgroundColor: '#000'
628
+ },
629
+ backdropTouchable: {
630
+ flex: 1
631
+ },
632
+ sheet: {
633
+ position: 'absolute',
634
+ bottom: 0,
635
+ overflow: 'hidden',
636
+ maxWidth: 800,
637
+ alignSelf: 'center',
638
+ marginHorizontal: 'auto'
639
+ },
640
+ sheetDetached: {
641
+ left: 16,
642
+ right: 16,
643
+ borderRadius: 24
644
+ },
645
+ sheetNormal: {
646
+ left: 0,
647
+ right: 0,
648
+ borderTopLeftRadius: 24,
649
+ borderTopRightRadius: 24
650
+ },
651
+ /** Legacy (non-manualActivation) handle: decorative overlay only. */
652
+ handle: {
653
+ position: 'absolute',
654
+ top: 10,
655
+ left: '50%',
656
+ marginLeft: -18,
657
+ width: 36,
658
+ height: 5,
659
+ borderRadius: 3,
660
+ zIndex: _zIndex.Z_INDEX.sheetHandle
661
+ },
662
+ /**
663
+ * Hit area for the drag handle in `manualActivation` mode. Absolutely
664
+ * positioned at the top of the sheet so the area visually "floats" above
665
+ * the content — content scrolls up underneath it (no layout offset)
666
+ * while the thumb can still grab the full-width 28dp strip to drag.
667
+ */
668
+ handleHitArea: {
669
+ position: 'absolute',
670
+ top: 0,
671
+ left: 0,
672
+ right: 0,
673
+ height: 28,
674
+ alignItems: 'center',
675
+ justifyContent: 'flex-start',
676
+ paddingTop: 6,
677
+ zIndex: _zIndex.Z_INDEX.sheetHandle
678
+ },
679
+ background: {
680
+ ..._reactNative.StyleSheet.absoluteFill
681
+ },
682
+ scrollView: {
683
+ flex: 1
684
+ },
685
+ scrollContent: {
686
+ flexGrow: 1
687
+ },
688
+ nonScrollableContent: {
689
+ flex: 1
690
+ }
691
+ });
692
+
693
+ // Create web scrollbar styles dynamically based on theme
694
+ const createWebScrollbarStyle = borderColor => {
695
+ if (_reactNative.Platform.OS !== 'web' || typeof document === 'undefined') return;
696
+ let styleElement = document.getElementById(SCROLLBAR_STYLE_ID);
697
+ if (!styleElement) {
698
+ styleElement = document.createElement('style');
699
+ styleElement.id = SCROLLBAR_STYLE_ID;
700
+ document.head.appendChild(styleElement);
701
+ }
702
+
703
+ // Derive a slightly darker scrollbar hover color from the border color
704
+ const scrollbarColor = borderColor;
705
+ const scrollbarHoverColor = borderColor.startsWith('hsl') ? borderColor.replace(/\)$/, ' / 0.7)') // add alpha for hover
706
+ : '#888';
707
+ styleElement.textContent = `
708
+ .bottom-sheet-scrollview::-webkit-scrollbar {
709
+ width: 6px;
710
+ }
711
+ .bottom-sheet-scrollview::-webkit-scrollbar-track {
712
+ background: transparent;
713
+ border-radius: 10px;
714
+ }
715
+ .bottom-sheet-scrollview::-webkit-scrollbar-thumb {
716
+ background: ${scrollbarColor};
717
+ border-radius: 10px;
718
+ }
719
+ .bottom-sheet-scrollview::-webkit-scrollbar-thumb:hover {
720
+ background: ${scrollbarHoverColor};
721
+ }
722
+ `;
723
+ };
724
+ const SCROLLBAR_STYLE_ID = 'bottom-sheet-scrollbar-style';
725
+
726
+ /** Remove the injected scrollbar <style> tag on unmount. */
727
+ const removeWebScrollbarStyle = () => {
728
+ if (_reactNative.Platform.OS !== 'web' || typeof document === 'undefined') return;
729
+ document.getElementById(SCROLLBAR_STYLE_ID)?.remove();
730
+ };
731
+ //# sourceMappingURL=BottomSheetBase.js.map