react-native-bottom-sheet-stack 1.9.1 → 1.10.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.
Files changed (85) hide show
  1. package/README.md +22 -8
  2. package/lib/commonjs/BottomSheetBackdrop.js +15 -17
  3. package/lib/commonjs/BottomSheetBackdrop.js.map +1 -1
  4. package/lib/commonjs/QueueItem.js +2 -0
  5. package/lib/commonjs/QueueItem.js.map +1 -1
  6. package/lib/commonjs/adapters/actions-sheet/ActionsSheetAdapter.js +18 -18
  7. package/lib/commonjs/adapters/actions-sheet/ActionsSheetAdapter.js.map +1 -1
  8. package/lib/commonjs/adapters/gorhom-sheet/GorhomSheetAdapter.js +14 -22
  9. package/lib/commonjs/adapters/gorhom-sheet/GorhomSheetAdapter.js.map +1 -1
  10. package/lib/commonjs/adapters/gorhom-sheet/index.js +6 -0
  11. package/lib/commonjs/adapters/gorhom-sheet/index.js.map +1 -1
  12. package/lib/commonjs/adapters/react-native-modal/ReactNativeModalAdapter.js +15 -17
  13. package/lib/commonjs/adapters/react-native-modal/ReactNativeModalAdapter.js.map +1 -1
  14. package/lib/commonjs/bottomSheetCoordinator.js +103 -0
  15. package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
  16. package/lib/commonjs/index.js +38 -34
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/onBeforeCloseRegistry.js +42 -0
  19. package/lib/commonjs/onBeforeCloseRegistry.js.map +1 -0
  20. package/lib/commonjs/store/hooks.js +24 -4
  21. package/lib/commonjs/store/hooks.js.map +1 -1
  22. package/lib/commonjs/store/store.js +8 -0
  23. package/lib/commonjs/store/store.js.map +1 -1
  24. package/lib/commonjs/useBottomSheetContext.js +31 -17
  25. package/lib/commonjs/useBottomSheetContext.js.map +1 -1
  26. package/lib/commonjs/useBottomSheetControl.js +46 -33
  27. package/lib/commonjs/useBottomSheetControl.js.map +1 -1
  28. package/lib/commonjs/useBottomSheetManager.js +16 -10
  29. package/lib/commonjs/useBottomSheetManager.js.map +1 -1
  30. package/lib/commonjs/useOnBeforeClose.js +107 -0
  31. package/lib/commonjs/useOnBeforeClose.js.map +1 -0
  32. package/lib/typescript/example/src/screens/HomeScreen.d.ts.map +1 -1
  33. package/lib/typescript/example/src/sheets/CloseInterceptionSheets.d.ts +14 -0
  34. package/lib/typescript/example/src/sheets/CloseInterceptionSheets.d.ts.map +1 -0
  35. package/lib/typescript/example/src/sheets/index.d.ts +1 -0
  36. package/lib/typescript/example/src/sheets/index.d.ts.map +1 -1
  37. package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -1
  38. package/lib/typescript/src/QueueItem.d.ts.map +1 -1
  39. package/lib/typescript/src/adapters/actions-sheet/ActionsSheetAdapter.d.ts.map +1 -1
  40. package/lib/typescript/src/adapters/gorhom-sheet/GorhomSheetAdapter.d.ts +1 -1
  41. package/lib/typescript/src/adapters/gorhom-sheet/GorhomSheetAdapter.d.ts.map +1 -1
  42. package/lib/typescript/src/adapters/gorhom-sheet/index.d.ts +4 -0
  43. package/lib/typescript/src/adapters/gorhom-sheet/index.d.ts.map +1 -1
  44. package/lib/typescript/src/adapters/react-native-modal/ReactNativeModalAdapter.d.ts.map +1 -1
  45. package/lib/typescript/src/bottomSheetCoordinator.d.ts +25 -0
  46. package/lib/typescript/src/bottomSheetCoordinator.d.ts.map +1 -1
  47. package/lib/typescript/src/index.d.ts +7 -9
  48. package/lib/typescript/src/index.d.ts.map +1 -1
  49. package/lib/typescript/src/onBeforeCloseRegistry.d.ts +26 -0
  50. package/lib/typescript/src/onBeforeCloseRegistry.d.ts.map +1 -0
  51. package/lib/typescript/src/store/hooks.d.ts +2 -0
  52. package/lib/typescript/src/store/hooks.d.ts.map +1 -1
  53. package/lib/typescript/src/store/store.d.ts.map +1 -1
  54. package/lib/typescript/src/store/types.d.ts +8 -0
  55. package/lib/typescript/src/store/types.d.ts.map +1 -1
  56. package/lib/typescript/src/useBottomSheetContext.d.ts +5 -0
  57. package/lib/typescript/src/useBottomSheetContext.d.ts.map +1 -1
  58. package/lib/typescript/src/useBottomSheetControl.d.ts +2 -0
  59. package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
  60. package/lib/typescript/src/useBottomSheetManager.d.ts +5 -0
  61. package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
  62. package/lib/typescript/src/useOnBeforeClose.d.ts +65 -0
  63. package/lib/typescript/src/useOnBeforeClose.d.ts.map +1 -0
  64. package/package.json +19 -1
  65. package/src/BottomSheetBackdrop.tsx +2 -3
  66. package/src/QueueItem.tsx +2 -0
  67. package/src/adapters/actions-sheet/ActionsSheetAdapter.tsx +6 -15
  68. package/src/adapters/gorhom-sheet/GorhomSheetAdapter.tsx +7 -18
  69. package/src/adapters/gorhom-sheet/index.ts +5 -0
  70. package/src/adapters/react-native-modal/ReactNativeModalAdapter.tsx +5 -14
  71. package/src/bottomSheetCoordinator.ts +128 -0
  72. package/src/index.tsx +17 -18
  73. package/src/onBeforeCloseRegistry.ts +44 -0
  74. package/src/store/hooks.ts +8 -0
  75. package/src/store/store.ts +10 -0
  76. package/src/store/types.ts +8 -0
  77. package/src/useBottomSheetContext.ts +11 -1
  78. package/src/useBottomSheetControl.ts +11 -8
  79. package/src/useBottomSheetManager.tsx +14 -8
  80. package/src/useOnBeforeClose.ts +92 -0
  81. package/lib/commonjs/BottomSheetManaged.js +0 -13
  82. package/lib/commonjs/BottomSheetManaged.js.map +0 -1
  83. package/lib/typescript/src/BottomSheetManaged.d.ts +0 -11
  84. package/lib/typescript/src/BottomSheetManaged.d.ts.map +0 -1
  85. package/src/BottomSheetManaged.tsx +0 -14
@@ -3,6 +3,11 @@ export interface UseBottomSheetContextReturn<TParams> {
3
3
  id: string;
4
4
  params: TParams;
5
5
  close: () => void;
6
+ /**
7
+ * Close the sheet, bypassing any onBeforeClose interceptor.
8
+ * Useful for force-closing from within onBeforeClose confirmation flows.
9
+ */
10
+ forceClose: () => void;
6
11
  /** @deprecated Use `close` instead */
7
12
  closeBottomSheet: () => void;
8
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useBottomSheetContext.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetContext.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,2BAA2B,CAAC,OAAO;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,sCAAsC;IACtC,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,gDAAgD;AAChD,wBAAgB,qBAAqB,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;AAC9E,2DAA2D;AAC3D,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,mBAAmB,KAC1B,2BAA2B,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AAwB7D;;GAEG;AACH,eAAO,MAAM,mBAAmB,8BAAwB,CAAC"}
1
+ {"version":3,"file":"useBottomSheetContext.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,2BAA2B,CAAC,OAAO;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,sCAAsC;IACtC,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,gDAAgD;AAChD,wBAAgB,qBAAqB,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;AAC9E,2DAA2D;AAC3D,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,mBAAmB,KAC1B,2BAA2B,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AA4B7D;;GAEG;AACH,eAAO,MAAM,mBAAmB,8BAAwB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { type OpenMode } from './bottomSheet.store';
2
2
  import type { BottomSheetPortalId, BottomSheetPortalParams, HasParams } from './portal.types';
3
+ import type { CloseAllOptions } from './useBottomSheetManager';
3
4
  interface BaseOpenOptions<TParams> {
4
5
  mode?: OpenMode;
5
6
  scaleBackground?: boolean;
@@ -14,6 +15,7 @@ type OpenFunction<T extends BottomSheetPortalId> = HasParams<T> extends true ? (
14
15
  export interface UseBottomSheetControlReturn<T extends BottomSheetPortalId> {
15
16
  open: OpenFunction<T>;
16
17
  close: () => void;
18
+ closeAll: (options?: CloseAllOptions) => Promise<void>;
17
19
  updateParams: (params: BottomSheetPortalParams<T>) => void;
18
20
  resetParams: () => void;
19
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useBottomSheetControl.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetControl.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACvB,SAAS,EACV,MAAM,gBAAgB,CAAC;AAGxB,UAAU,eAAe,CAAC,OAAO;IAC/B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,KAAK,WAAW,CAAC,CAAC,SAAS,mBAAmB,IAAI,IAAI,CACpD,eAAe,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,EAC3C,QAAQ,CACT,GACC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,GACtB;IAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;CAAE,GACtC;IAAE,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAAC;AAE/C,KAAK,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAC7C,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GACjC,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEzC,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,mBAAmB;IACxE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,YAAY,EAAE,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3D,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,mBAAmB,EACjE,EAAE,EAAE,CAAC,GACJ,2BAA2B,CAAC,CAAC,CAAC,CAgDhC"}
1
+ {"version":3,"file":"useBottomSheetControl.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetControl.ts"],"names":[],"mappings":"AAGA,OAAO,EAA4B,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACvB,SAAS,EACV,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,UAAU,eAAe,CAAC,OAAO;IAC/B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,KAAK,WAAW,CAAC,CAAC,SAAS,mBAAmB,IAAI,IAAI,CACpD,eAAe,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,EAC3C,QAAQ,CACT,GACC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,GACtB;IAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;CAAE,GACtC;IAAE,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAAC;AAE/C,KAAK,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAC7C,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GACjC,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEzC,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,mBAAmB;IACxE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,YAAY,EAAE,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3D,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,mBAAmB,EACjE,EAAE,EAAE,CAAC,GACJ,2BAA2B,CAAC,CAAC,CAAC,CAqDhC"}
@@ -1,5 +1,9 @@
1
1
  import React from 'react';
2
2
  import { type OpenMode } from './bottomSheet.store';
3
+ export interface CloseAllOptions {
4
+ /** Delay in ms between each cascading close animation. Default: 100 */
5
+ stagger?: number;
6
+ }
3
7
  export declare const useBottomSheetManager: () => {
4
8
  open: (content: React.ReactElement, options?: {
5
9
  id?: string;
@@ -8,6 +12,7 @@ export declare const useBottomSheetManager: () => {
8
12
  scaleBackground?: boolean;
9
13
  }) => string;
10
14
  close: (id: string) => void;
15
+ closeAll: (options?: CloseAllOptions) => Promise<void>;
11
16
  clear: () => void;
12
17
  /** @deprecated Use `open` instead */
13
18
  openBottomSheet: (content: React.ReactElement, options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"useBottomSheetManager.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAC;AAK7B,eAAO,MAAM,qBAAqB;oBAQrB,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;gBA2BgB,MAAM;;IAavB,qCAAqC;+BA9C5B,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;IA0CD,sCAAsC;;CAGzC,CAAC"}
1
+ {"version":3,"file":"useBottomSheetManager.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM5E,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,qBAAqB;oBAOrB,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;gBA2BgB,MAAM;yBAIG,eAAe;;IAezC,qCAAqC;+BApD5B,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;IAgDD,sCAAsC;;CAGzC,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { OnBeforeCloseCallback } from './onBeforeCloseRegistry';
2
+ /**
3
+ * Registers an interceptor that is called before the sheet closes.
4
+ *
5
+ * When active, this hook:
6
+ * 1. Sets `preventDismiss` on the sheet so adapters block user-initiated
7
+ * gestures (swipe down, pan-to-close) at the native level.
8
+ * 2. Intercepts all programmatic close paths (backdrop tap, back button,
9
+ * `close()`, `closeAll()`) and calls the callback first.
10
+ *
11
+ * The interceptor receives `onConfirm` and `onCancel` callbacks. Call these
12
+ * when the user makes a decision. This works seamlessly with `Alert.alert`:
13
+ *
14
+ * ```tsx
15
+ * useOnBeforeClose(({ onConfirm, onCancel }) => {
16
+ * if (dirty) {
17
+ * Alert.alert('Discard changes?', '', [
18
+ * { text: 'Cancel', onPress: onCancel },
19
+ * { text: 'Discard', onPress: onConfirm },
20
+ * ]);
21
+ * } else {
22
+ * onConfirm(); // Allow close immediately
23
+ * }
24
+ * });
25
+ * ```
26
+ *
27
+ * For backward compatibility, you can still return `boolean` or `Promise<boolean>`:
28
+ * - Return `false` (or resolve to `false`) to prevent closing
29
+ * - Return `true` (or resolve to `true`) to allow closing
30
+ *
31
+ * Use `forceClose()` from `useBottomSheetContext` to bypass the interceptor entirely.
32
+ *
33
+ * Must be used inside a sheet component (within BottomSheetContext).
34
+ *
35
+ * @example Callback pattern (recommended)
36
+ * ```tsx
37
+ * function MySheet() {
38
+ * const [dirty, setDirty] = useState(false);
39
+ *
40
+ * useOnBeforeClose(({ onConfirm, onCancel }) => {
41
+ * if (dirty) {
42
+ * Alert.alert('Discard changes?', '', [
43
+ * { text: 'Cancel', style: 'cancel', onPress: onCancel },
44
+ * { text: 'Discard', onPress: onConfirm },
45
+ * ]);
46
+ * } else {
47
+ * onConfirm();
48
+ * }
49
+ * });
50
+ * }
51
+ * ```
52
+ *
53
+ * @example Boolean return (backward compatible)
54
+ * ```tsx
55
+ * function MySheet() {
56
+ * const [dirty, setDirty] = useState(false);
57
+ *
58
+ * useOnBeforeClose(() => {
59
+ * return !dirty; // false blocks, true allows
60
+ * });
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function useOnBeforeClose(callback: OnBeforeCloseCallback): void;
65
+ //# sourceMappingURL=useOnBeforeClose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnBeforeClose.d.ts","sourceRoot":"","sources":["../../../src/useOnBeforeClose.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAqBtE"}
package/package.json CHANGED
@@ -1,10 +1,28 @@
1
1
  {
2
2
  "name": "react-native-bottom-sheet-stack",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Bottom Sheet Stack Manager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "lib/commonjs/index.js",
7
7
  "types": "lib/typescript/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/commonjs/index.js"
12
+ },
13
+ "./gorhom": {
14
+ "types": "./lib/typescript/src/adapters/gorhom-sheet/index.d.ts",
15
+ "default": "./lib/commonjs/adapters/gorhom-sheet/index.js"
16
+ },
17
+ "./react-native-modal": {
18
+ "types": "./lib/typescript/src/adapters/react-native-modal/index.d.ts",
19
+ "default": "./lib/commonjs/adapters/react-native-modal/index.js"
20
+ },
21
+ "./actions-sheet": {
22
+ "types": "./lib/typescript/src/adapters/actions-sheet/index.d.ts",
23
+ "default": "./lib/commonjs/adapters/actions-sheet/index.js"
24
+ }
25
+ },
8
26
  "files": [
9
27
  "src",
10
28
  "lib/typescript",
@@ -6,7 +6,7 @@ import Animated, {
6
6
  useAnimatedStyle,
7
7
  } from 'react-native-reanimated';
8
8
  import { getAnimatedIndex } from './animatedRegistry';
9
- import { useStartClosing } from './store';
9
+ import { requestClose } from './bottomSheetCoordinator';
10
10
 
11
11
  interface BottomSheetBackdropProps {
12
12
  sheetId: string;
@@ -14,7 +14,6 @@ interface BottomSheetBackdropProps {
14
14
 
15
15
  export function BottomSheetBackdrop({ sheetId }: BottomSheetBackdropProps) {
16
16
  const animatedIndex = getAnimatedIndex(sheetId);
17
- const startClosing = useStartClosing();
18
17
 
19
18
  if (!animatedIndex) {
20
19
  throw new Error('animatedIndex must be defined in BottomSheetBackdrop');
@@ -46,7 +45,7 @@ export function BottomSheetBackdrop({ sheetId }: BottomSheetBackdropProps) {
46
45
  return (
47
46
  <Pressable
48
47
  style={StyleSheet.absoluteFillObject}
49
- onPress={() => startClosing(sheetId)}
48
+ onPress={() => requestClose(sheetId)}
50
49
  >
51
50
  <Animated.View
52
51
  style={[StyleSheet.absoluteFillObject, animatedStyle, styles.backdrop]}
package/src/QueueItem.tsx CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  useSheetUsePortal,
14
14
  } from './bottomSheet.store';
15
15
  import { BottomSheetBackdrop } from './BottomSheetBackdrop';
16
+ import { removeOnBeforeClose } from './onBeforeCloseRegistry';
16
17
  import { cleanupSheetRef } from './refsMap';
17
18
  import { useSheetScaleAnimatedStyle } from './useScaleAnimation';
18
19
 
@@ -40,6 +41,7 @@ export const QueueItem = memo(function QueueItem({
40
41
  return () => {
41
42
  cleanupSheetRef(id);
42
43
  cleanupAnimatedIndex(id);
44
+ removeOnBeforeClose(id);
43
45
  };
44
46
  }, [id, keepMounted]);
45
47
 
@@ -1,17 +1,13 @@
1
1
  import React, { useImperativeHandle, useRef } from 'react';
2
2
 
3
3
  import type { SheetAdapterRef } from '../../adapter.types';
4
+ import { useSheetPreventDismiss } from '../../bottomSheet.store';
4
5
  import { createSheetEventHandlers } from '../../bottomSheetCoordinator';
5
6
  import { useAdapterRef } from '../../useAdapterRef';
6
7
  import { useAnimatedIndex } from '../../useAnimatedIndex';
7
8
  import { useBottomSheetContext } from '../../useBottomSheetContext';
8
9
 
9
- let ActionSheet: any;
10
- try {
11
- ActionSheet = require('react-native-actions-sheet').default;
12
- } catch {
13
- // Optional dependency — resolved lazily when the adapter renders.
14
- }
10
+ const ActionSheet = require('react-native-actions-sheet').default;
15
11
 
16
12
  /**
17
13
  * Adapter for `react-native-actions-sheet` — a zero-dependency action sheet
@@ -37,15 +33,10 @@ export const ActionsSheetAdapter = React.forwardRef<
37
33
  SheetAdapterRef,
38
34
  ActionsSheetAdapterProps
39
35
  >(({ children, ...sheetProps }, forwardedRef) => {
40
- if (!ActionSheet) {
41
- throw new Error(
42
- 'ActionsSheetAdapter requires "react-native-actions-sheet". Install it with: yarn add react-native-actions-sheet'
43
- );
44
- }
45
-
46
36
  const { id } = useBottomSheetContext();
47
37
  const ref = useAdapterRef(forwardedRef);
48
38
  const animatedIndex = useAnimatedIndex();
39
+ const preventDismiss = useSheetPreventDismiss(id);
49
40
 
50
41
  const actionSheetRef = useRef<any>(null);
51
42
 
@@ -74,9 +65,9 @@ export const ActionsSheetAdapter = React.forwardRef<
74
65
  return (
75
66
  <ActionSheet
76
67
  // Adapter defaults (overridable via spread)
77
- gestureEnabled
78
- closeOnTouchBackdrop
79
- closeOnPressBack
68
+ gestureEnabled={!preventDismiss}
69
+ closeOnTouchBackdrop={!preventDismiss}
70
+ closeOnPressBack={!preventDismiss}
80
71
  keyboardHandlerEnabled
81
72
  {...sheetProps}
82
73
  // Managed by adapter (not overridable)
@@ -1,9 +1,13 @@
1
- import type { BottomSheetProps } from '@gorhom/bottom-sheet';
1
+ import BottomSheetOriginal, {
2
+ useBottomSheetSpringConfigs,
3
+ type BottomSheetProps,
4
+ } from '@gorhom/bottom-sheet';
2
5
  import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
3
6
  import React, { useImperativeHandle, useRef } from 'react';
4
7
  import { useAnimatedReaction } from 'react-native-reanimated';
5
8
 
6
9
  import type { SheetAdapterRef } from '../../adapter.types';
10
+ import { useSheetPreventDismiss } from '../../bottomSheet.store';
7
11
  import { createSheetEventHandlers } from '../../bottomSheetCoordinator';
8
12
  import { useBottomSheetDefaultIndex } from '../../BottomSheetDefaultIndex.context';
9
13
  import { useAdapterRef } from '../../useAdapterRef';
@@ -11,16 +15,6 @@ import { useAnimatedIndex } from '../../useAnimatedIndex';
11
15
  import { useBackHandler } from '../../useBackHandler';
12
16
  import { useBottomSheetContext } from '../../useBottomSheetContext';
13
17
 
14
- let BottomSheetOriginal: any;
15
- let useBottomSheetSpringConfigs: any;
16
- try {
17
- const gorhom = require('@gorhom/bottom-sheet');
18
- BottomSheetOriginal = gorhom.default;
19
- useBottomSheetSpringConfigs = gorhom.useBottomSheetSpringConfigs;
20
- } catch {
21
- // Optional dependency — resolved lazily when the adapter renders.
22
- }
23
-
24
18
  export interface GorhomSheetAdapterProps extends BottomSheetProps {}
25
19
 
26
20
  const nullBackdrop = () => null;
@@ -42,16 +36,11 @@ export const GorhomSheetAdapter = React.forwardRef<
42
36
  },
43
37
  forwardedRef
44
38
  ) => {
45
- if (!BottomSheetOriginal) {
46
- throw new Error(
47
- 'GorhomSheetAdapter requires "@gorhom/bottom-sheet". Install it with: yarn add @gorhom/bottom-sheet react-native-gesture-handler'
48
- );
49
- }
50
-
51
39
  const { id } = useBottomSheetContext();
52
40
  const ref = useAdapterRef(forwardedRef);
53
41
  const contextAnimatedIndex = useAnimatedIndex();
54
42
  const defaultIndex = useBottomSheetDefaultIndex();
43
+ const preventDismiss = useSheetPreventDismiss(id);
55
44
 
56
45
  const gorhomRef = useRef<BottomSheetMethods | null>(null);
57
46
 
@@ -123,7 +112,7 @@ export const GorhomSheetAdapter = React.forwardRef<
123
112
  onClose={wrappedOnClose}
124
113
  onAnimate={wrappedOnAnimate}
125
114
  backdropComponent={backdropComponent}
126
- enablePanDownToClose={enablePanDownToClose}
115
+ enablePanDownToClose={preventDismiss ? false : enablePanDownToClose}
127
116
  >
128
117
  {children}
129
118
  </BottomSheetOriginal>
@@ -2,3 +2,8 @@ export {
2
2
  GorhomSheetAdapter,
3
3
  type GorhomSheetAdapterProps,
4
4
  } from './GorhomSheetAdapter';
5
+
6
+ /** @deprecated Use `GorhomSheetAdapter` instead. */
7
+ export { GorhomSheetAdapter as BottomSheetManaged } from './GorhomSheetAdapter';
8
+ /** @deprecated Use `GorhomSheetAdapterProps` instead. */
9
+ export { type GorhomSheetAdapterProps as BottomSheetManagedProps } from './GorhomSheetAdapter';
@@ -1,17 +1,13 @@
1
1
  import React, { useImperativeHandle, useState } from 'react';
2
2
 
3
3
  import type { SheetAdapterRef } from '../../adapter.types';
4
+ import { useSheetPreventDismiss } from '../../bottomSheet.store';
4
5
  import { createSheetEventHandlers } from '../../bottomSheetCoordinator';
5
6
  import { useAdapterRef } from '../../useAdapterRef';
6
7
  import { useAnimatedIndex } from '../../useAnimatedIndex';
7
8
  import { useBottomSheetContext } from '../../useBottomSheetContext';
8
9
 
9
- let RNModal: any;
10
- try {
11
- RNModal = require('react-native-modal').default;
12
- } catch {
13
- // Optional dependency — resolved lazily when the adapter renders.
14
- }
10
+ const RNModal = require('react-native-modal').default;
15
11
 
16
12
  /**
17
13
  * Adapter for `react-native-modal`.
@@ -36,15 +32,10 @@ export const ReactNativeModalAdapter = React.forwardRef<
36
32
  SheetAdapterRef,
37
33
  ReactNativeModalAdapterProps
38
34
  >(({ children, ...modalProps }, forwardedRef) => {
39
- if (!RNModal) {
40
- throw new Error(
41
- 'ReactNativeModalAdapter requires "react-native-modal". Install it with: yarn add react-native-modal'
42
- );
43
- }
44
-
45
35
  const { id } = useBottomSheetContext();
46
36
  const ref = useAdapterRef(forwardedRef);
47
37
  const animatedIndex = useAnimatedIndex();
38
+ const preventDismiss = useSheetPreventDismiss(id);
48
39
  const [isVisible, setIsVisible] = useState(false);
49
40
 
50
41
  const { handleDismiss, handleOpened, handleClosed } =
@@ -68,7 +59,7 @@ export const ReactNativeModalAdapter = React.forwardRef<
68
59
  return (
69
60
  <RNModal
70
61
  // Adapter defaults (overridable via spread)
71
- swipeDirection="down"
62
+ swipeDirection={preventDismiss ? undefined : 'down'}
72
63
  useNativeDriver
73
64
  hideModalContentWhileAnimating
74
65
  {...modalProps}
@@ -82,7 +73,7 @@ export const ReactNativeModalAdapter = React.forwardRef<
82
73
  onModalShow={handleOpened}
83
74
  onModalHide={handleClosed}
84
75
  onBackButtonPress={handleDismiss}
85
- onSwipeComplete={handleDismiss}
76
+ onSwipeComplete={preventDismiss ? undefined : handleDismiss}
86
77
  >
87
78
  {children}
88
79
  </RNModal>
@@ -1,5 +1,6 @@
1
1
  import type { SheetAdapterEvents } from './adapter.types';
2
2
  import { useBottomSheetStore } from './bottomSheet.store';
3
+ import { getOnBeforeClose } from './onBeforeCloseRegistry';
3
4
  import { getSheetRef } from './refsMap';
4
5
 
5
6
  /**
@@ -42,6 +43,126 @@ export function initBottomSheetCoordinator(groupId: string) {
42
43
  );
43
44
  }
44
45
 
46
+ /**
47
+ * Attempts to close a sheet, respecting the onBeforeClose interceptor.
48
+ *
49
+ * If an onBeforeClose callback is registered for the sheet and it returns
50
+ * `false` (or resolves to `false`), the close is cancelled.
51
+ *
52
+ * @returns `true` if the close proceeded, `false` if it was intercepted.
53
+ */
54
+ export async function requestClose(sheetId: string): Promise<boolean> {
55
+ const state = useBottomSheetStore.getState();
56
+ const currentStatus = state.sheetsById[sheetId]?.status;
57
+
58
+ // Don't run interceptor if sheet is already closing
59
+ // This prevents duplicate interceptor calls during close animations
60
+ if (currentStatus === 'closing') {
61
+ return false;
62
+ }
63
+
64
+ const interceptor = getOnBeforeClose(sheetId);
65
+
66
+ if (interceptor) {
67
+ try {
68
+ const allowed = await new Promise<boolean>((resolve) => {
69
+ const result = interceptor({
70
+ onConfirm: () => resolve(true),
71
+ onCancel: () => resolve(false),
72
+ });
73
+
74
+ if (result) {
75
+ if (typeof result === 'boolean') {
76
+ resolve(result);
77
+ } else if (
78
+ result &&
79
+ typeof result === 'object' &&
80
+ 'then' in result &&
81
+ typeof result.then === 'function'
82
+ ) {
83
+ // It's a Promise
84
+ result.then(resolve);
85
+ }
86
+ }
87
+ });
88
+
89
+ if (!allowed) {
90
+ return false;
91
+ }
92
+ } catch (error) {
93
+ // If the interceptor throws, cancel the close for safety
94
+ if (__DEV__) {
95
+ console.warn(
96
+ `[BottomSheet] onBeforeClose interceptor threw an error for sheet "${sheetId}". ` +
97
+ 'Close cancelled for safety. Fix the interceptor to avoid this warning.',
98
+ error
99
+ );
100
+ }
101
+ return false;
102
+ }
103
+ }
104
+
105
+ if (currentStatus === 'open' || currentStatus === 'opening') {
106
+ state.startClosing(sheetId);
107
+ }
108
+
109
+ return true;
110
+ }
111
+
112
+ /**
113
+ * Default stagger delay between cascading close animations (ms).
114
+ */
115
+ const DEFAULT_STAGGER_MS = 100;
116
+
117
+ /**
118
+ * Closes all sheets in a group from top to bottom with cascading animation.
119
+ *
120
+ * Each sheet is closed with a staggered delay so the user sees them
121
+ * peel off one-by-one (similar to `popToRoot` in React Navigation).
122
+ *
123
+ * If a sheet has an `onBeforeClose` interceptor that rejects, the cascade
124
+ * stops at that sheet — sheets below it remain open.
125
+ *
126
+ * @param groupId - The manager group to close sheets in.
127
+ * @param options.stagger - Delay in ms between each close (default: 100).
128
+ * @returns A promise that resolves when the cascade finishes (or is stopped).
129
+ */
130
+ export async function closeAllAnimated(
131
+ groupId: string,
132
+ options?: { stagger?: number }
133
+ ): Promise<void> {
134
+ const stagger = options?.stagger ?? DEFAULT_STAGGER_MS;
135
+
136
+ const state = useBottomSheetStore.getState();
137
+ const groupSheetIds = state.stackOrder.filter(
138
+ (id) => state.sheetsById[id]?.groupId === groupId
139
+ );
140
+
141
+ // Close from top to bottom (reverse order)
142
+ const reversed = [...groupSheetIds].reverse();
143
+
144
+ for (const sheetId of reversed) {
145
+ const currentState = useBottomSheetStore.getState();
146
+ const sheet = currentState.sheetsById[sheetId];
147
+
148
+ // Skip sheets that are already closing or hidden
149
+ if (!sheet || sheet.status === 'closing' || sheet.status === 'hidden') {
150
+ continue;
151
+ }
152
+
153
+ const closed = await requestClose(sheetId);
154
+
155
+ if (!closed) {
156
+ // Interceptor blocked — stop the cascade
157
+ break;
158
+ }
159
+
160
+ if (stagger > 0 && reversed.indexOf(sheetId) < reversed.length - 1) {
161
+ await new Promise<void>((resolve) => setTimeout(resolve, stagger));
162
+ }
163
+ }
164
+ }
165
+
45
166
  /**
46
167
  * Creates event handlers that adapters call to sync UI state back to the store.
47
168
  * Direction: Adapter Events → Store
@@ -53,6 +174,13 @@ export function initBottomSheetCoordinator(groupId: string) {
53
174
  */
54
175
  export function createSheetEventHandlers(sheetId: string): SheetAdapterEvents {
55
176
  const handleDismiss = () => {
177
+ const interceptor = getOnBeforeClose(sheetId);
178
+
179
+ if (interceptor) {
180
+ requestClose(sheetId);
181
+ return;
182
+ }
183
+
56
184
  const state = useBottomSheetStore.getState();
57
185
  const currentStatus = state.sheetsById[sheetId]?.status;
58
186
 
package/src/index.tsx CHANGED
@@ -2,46 +2,39 @@
2
2
  export { BottomSheetManagerProvider } from './BottomSheetManager.provider';
3
3
  export { BottomSheetHost } from './BottomSheetHost';
4
4
  export { BottomSheetScaleView } from './BottomSheetScaleView';
5
- export { BottomSheetManaged, type BottomSheetRef } from './BottomSheetManaged';
6
5
  export { BottomSheetPortal } from './BottomSheetPortal';
7
6
  export { BottomSheetPersistent } from './BottomSheetPersistent';
8
7
 
9
- // Adapters
10
- export {
11
- GorhomSheetAdapter,
12
- type GorhomSheetAdapterProps,
13
- } from './adapters/gorhom-sheet';
8
+ // Adapters (only those with zero 3rd-party deps)
14
9
  export {
15
10
  CustomModalAdapter,
16
11
  type ModalAdapterProps,
17
12
  } from './adapters/custom-modal';
18
- /** @deprecated Use `CustomModalAdapter` instead. */
19
- export { ModalAdapter } from './adapters/custom-modal';
20
- export {
21
- ReactNativeModalAdapter,
22
- type ReactNativeModalAdapterProps,
23
- } from './adapters/react-native-modal';
24
- export {
25
- ActionsSheetAdapter,
26
- type ActionsSheetAdapterProps,
27
- } from './adapters/actions-sheet';
28
13
 
29
14
  // Adapter types
30
15
  export type {
31
16
  SheetAdapterRef,
17
+ SheetAdapterRef as BottomSheetRef,
32
18
  SheetAdapterEvents,
33
19
  SheetRef,
34
20
  } from './adapter.types';
35
21
 
36
22
  // Adapter utilities (for custom adapter authors)
37
- export { createSheetEventHandlers } from './bottomSheetCoordinator';
23
+ export {
24
+ createSheetEventHandlers,
25
+ requestClose,
26
+ closeAllAnimated,
27
+ } from './bottomSheetCoordinator';
38
28
  export { useAdapterRef } from './useAdapterRef';
39
29
  export { useAnimatedIndex } from './useAnimatedIndex';
40
30
  export { useBackHandler } from './useBackHandler';
41
31
  export { getAnimatedIndex, setAnimatedIndexValue } from './animatedRegistry';
42
32
 
43
33
  // Hooks
44
- export { useBottomSheetManager } from './useBottomSheetManager';
34
+ export {
35
+ useBottomSheetManager,
36
+ type CloseAllOptions,
37
+ } from './useBottomSheetManager';
45
38
  export {
46
39
  useBottomSheetControl,
47
40
  type UseBottomSheetControlReturn,
@@ -55,6 +48,7 @@ export {
55
48
  useBottomSheetStatus,
56
49
  type UseBottomSheetStatusReturn,
57
50
  } from './useBottomSheetStatus';
51
+ export { useOnBeforeClose } from './useOnBeforeClose';
58
52
 
59
53
  // Types
60
54
  export type { ScaleConfig, ScaleAnimationConfig } from './useScaleAnimation';
@@ -71,6 +65,10 @@ export type {
71
65
 
72
66
  export { useBottomSheetStore } from './bottomSheet.store';
73
67
 
68
+ // onBeforeClose registry
69
+ export type { OnBeforeCloseCallback } from './onBeforeCloseRegistry';
70
+ export { setOnBeforeClose, removeOnBeforeClose } from './onBeforeCloseRegistry';
71
+
74
72
  // Testing utilities (internal use)
75
73
  export { __resetSheetRefs } from './refsMap';
76
74
  export {
@@ -78,3 +76,4 @@ export {
78
76
  __getAllAnimatedIndexes,
79
77
  } from './animatedRegistry';
80
78
  export { __resetPortalSessions } from './portalSessionRegistry';
79
+ export { __resetOnBeforeClose } from './onBeforeCloseRegistry';
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Registry for onBeforeClose interceptors.
3
+ *
4
+ * Callbacks are keyed by sheet ID. When a sheet is about to close,
5
+ * the coordinator checks this registry and calls the interceptor.
6
+ *
7
+ * The interceptor receives `onConfirm` and `onCancel` callbacks that
8
+ * should be called when the user makes a decision. Alternatively, it can
9
+ * return `boolean` or `Promise<boolean>` for backward compatibility.
10
+ *
11
+ * If the interceptor returns `false` (or resolves to `false`), or if
12
+ * `onCancel()` is called, the close is cancelled.
13
+ */
14
+ export type OnBeforeCloseCallback = (context: {
15
+ onConfirm: () => void;
16
+ onCancel: () => void;
17
+ }) => void | boolean | Promise<boolean>;
18
+
19
+ const onBeforeCloseMap = new Map<string, OnBeforeCloseCallback>();
20
+
21
+ export function getOnBeforeClose(
22
+ sheetId: string
23
+ ): OnBeforeCloseCallback | undefined {
24
+ return onBeforeCloseMap.get(sheetId);
25
+ }
26
+
27
+ export function setOnBeforeClose(
28
+ sheetId: string,
29
+ callback: OnBeforeCloseCallback
30
+ ): void {
31
+ onBeforeCloseMap.set(sheetId, callback);
32
+ }
33
+
34
+ export function removeOnBeforeClose(sheetId: string): void {
35
+ onBeforeCloseMap.delete(sheetId);
36
+ }
37
+
38
+ /**
39
+ * Reset all interceptors. Useful for testing.
40
+ * @internal
41
+ */
42
+ export function __resetOnBeforeClose(): void {
43
+ onBeforeCloseMap.clear();
44
+ }