react-native-bottom-sheet-stack 1.5.0 → 1.5.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 (50) hide show
  1. package/lib/commonjs/BottomSheetHost.js +29 -26
  2. package/lib/commonjs/BottomSheetHost.js.map +1 -1
  3. package/lib/commonjs/BottomSheetManaged.js +1 -1
  4. package/lib/commonjs/BottomSheetManaged.js.map +1 -1
  5. package/lib/commonjs/BottomSheetPortal.js +2 -3
  6. package/lib/commonjs/BottomSheetPortal.js.map +1 -1
  7. package/lib/commonjs/bottomSheet.store.js +16 -0
  8. package/lib/commonjs/bottomSheet.store.js.map +1 -1
  9. package/lib/commonjs/bottomSheetCoordinator.js +2 -2
  10. package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
  11. package/lib/commonjs/index.js +17 -4
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/refsMap.js +13 -2
  14. package/lib/commonjs/refsMap.js.map +1 -1
  15. package/lib/commonjs/useBottomSheetControl.js +47 -62
  16. package/lib/commonjs/useBottomSheetControl.js.map +1 -1
  17. package/lib/commonjs/useBottomSheetManager.js +22 -18
  18. package/lib/commonjs/useBottomSheetManager.js.map +1 -1
  19. package/lib/commonjs/useBottomSheetState.js +12 -4
  20. package/lib/commonjs/useBottomSheetState.js.map +1 -1
  21. package/lib/commonjs/useBottomSheetStatus.js +35 -0
  22. package/lib/commonjs/useBottomSheetStatus.js.map +1 -0
  23. package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
  24. package/lib/typescript/src/BottomSheetPortal.d.ts.map +1 -1
  25. package/lib/typescript/src/bottomSheet.store.d.ts +1 -0
  26. package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
  27. package/lib/typescript/src/index.d.ts +8 -6
  28. package/lib/typescript/src/index.d.ts.map +1 -1
  29. package/lib/typescript/src/refsMap.d.ts +6 -1
  30. package/lib/typescript/src/refsMap.d.ts.map +1 -1
  31. package/lib/typescript/src/useBottomSheetControl.d.ts +1 -3
  32. package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
  33. package/lib/typescript/src/useBottomSheetManager.d.ts +10 -1
  34. package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
  35. package/lib/typescript/src/useBottomSheetState.d.ts +11 -7
  36. package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
  37. package/lib/typescript/src/useBottomSheetStatus.d.ts +8 -0
  38. package/lib/typescript/src/useBottomSheetStatus.d.ts.map +1 -0
  39. package/package.json +1 -1
  40. package/src/BottomSheetHost.tsx +5 -3
  41. package/src/BottomSheetManaged.tsx +2 -2
  42. package/src/BottomSheetPortal.tsx +6 -5
  43. package/src/bottomSheet.store.ts +24 -0
  44. package/src/bottomSheetCoordinator.ts +3 -3
  45. package/src/index.tsx +27 -6
  46. package/src/refsMap.ts +16 -4
  47. package/src/useBottomSheetControl.ts +3 -15
  48. package/src/useBottomSheetManager.tsx +15 -9
  49. package/src/useBottomSheetState.ts +19 -17
  50. package/src/useBottomSheetStatus.ts +25 -0
@@ -1,18 +1,14 @@
1
1
  import React from 'react';
2
2
  import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
3
3
 
4
- import {
5
- useBottomSheetStore,
6
- type BottomSheetStatus,
7
- type OpenMode,
8
- } from './bottomSheet.store';
4
+ import { useBottomSheetStore, type OpenMode } from './bottomSheet.store';
9
5
  import { useMaybeBottomSheetManagerContext } from './BottomSheetManager.provider';
10
6
  import type {
11
7
  BottomSheetPortalId,
12
8
  BottomSheetPortalParams,
13
9
  HasParams,
14
10
  } from './portal.types';
15
- import { sheetRefs } from './refsMap';
11
+ import { setSheetRef } from './refsMap';
16
12
 
17
13
  interface BaseOpenOptions<TParams> {
18
14
  mode?: OpenMode;
@@ -38,8 +34,6 @@ export interface UseBottomSheetControlReturn<T extends BottomSheetPortalId> {
38
34
  close: () => void;
39
35
  updateParams: (params: BottomSheetPortalParams<T>) => void;
40
36
  resetParams: () => void;
41
- isOpen: boolean;
42
- status: BottomSheetStatus | null;
43
37
  }
44
38
 
45
39
  export function useBottomSheetControl<T extends BottomSheetPortalId>(
@@ -50,14 +44,13 @@ export function useBottomSheetControl<T extends BottomSheetPortalId>(
50
44
  const storeOpen = useBottomSheetStore((state) => state.open);
51
45
  const startClosing = useBottomSheetStore((state) => state.startClosing);
52
46
  const storeUpdateParams = useBottomSheetStore((state) => state.updateParams);
53
- const sheetState = useBottomSheetStore((state) => state.sheetsById[id]);
54
47
 
55
48
  const open = (options?: OpenOptions<T>) => {
56
49
  const groupId = bottomSheetManagerContext?.groupId || 'default';
57
50
 
58
51
  // Create ref when opening (same pattern as useBottomSheetManager)
59
52
  const ref = React.createRef<BottomSheetMethods>();
60
- sheetRefs[id] = ref;
53
+ setSheetRef(id, ref);
61
54
 
62
55
  storeOpen(
63
56
  {
@@ -84,15 +77,10 @@ export function useBottomSheetControl<T extends BottomSheetPortalId>(
84
77
  storeUpdateParams(id, undefined);
85
78
  };
86
79
 
87
- const status = sheetState?.status ?? null;
88
- const isOpen = status === 'open' || status === 'opening';
89
-
90
80
  return {
91
81
  open: open as OpenFunction<T>,
92
82
  close,
93
83
  updateParams,
94
84
  resetParams,
95
- isOpen,
96
- status,
97
85
  };
98
86
  }
@@ -2,17 +2,17 @@ import React from 'react';
2
2
 
3
3
  import { useBottomSheetStore, type OpenMode } from './bottomSheet.store';
4
4
  import { useMaybeBottomSheetManagerContext } from './BottomSheetManager.provider';
5
- import { sheetRefs } from './refsMap';
5
+ import { setSheetRef } from './refsMap';
6
6
  import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
7
7
  import { shallow } from 'zustand/shallow';
8
8
 
9
9
  export const useBottomSheetManager = () => {
10
10
  const bottomSheetManagerContext = useMaybeBottomSheetManagerContext();
11
11
 
12
- const { storeOpen, startClosing, storeClearAll } = useBottomSheetStore(
12
+ const { storeOpen, startClosing, storeClearGroup } = useBottomSheetStore(
13
13
  (store) => ({
14
14
  storeOpen: store.open,
15
- storeClearAll: store.clearAll,
15
+ storeClearGroup: store.clearGroup,
16
16
  startClosing: store.startClosing,
17
17
  }),
18
18
  shallow
@@ -33,10 +33,11 @@ export const useBottomSheetManager = () => {
33
33
  const id = options.id || Math.random().toString(36);
34
34
  const ref = React.createRef<BottomSheetMethods>();
35
35
 
36
- sheetRefs[id] = ref;
36
+ setSheetRef(id, ref);
37
37
 
38
- // @ts-ignore
39
- const contentWithRef = React.cloneElement(content, { ref });
38
+ const contentWithRef = React.cloneElement(content, {
39
+ ref,
40
+ } as { ref: typeof ref });
40
41
 
41
42
  storeOpen(
42
43
  {
@@ -55,13 +56,18 @@ export const useBottomSheetManager = () => {
55
56
  startClosing(id);
56
57
  };
57
58
 
58
- const clearAll = () => {
59
- storeClearAll();
59
+ const clear = () => {
60
+ const groupId = bottomSheetManagerContext?.groupId || 'default';
61
+ storeClearGroup(groupId);
60
62
  };
61
63
 
62
64
  return {
63
- clearAll,
65
+ open: openBottomSheet,
64
66
  close,
67
+ clear,
68
+ /** @deprecated Use `open` instead */
65
69
  openBottomSheet,
70
+ /** @deprecated Use `clear` instead */
71
+ clearAll: clear,
66
72
  };
67
73
  };
@@ -8,26 +8,23 @@ import type {
8
8
  BottomSheetPortalParams,
9
9
  } from './portal.types';
10
10
 
11
- // Marker type to detect when no generic is provided
12
- declare const UNSPECIFIED: unique symbol;
13
- type Unspecified = typeof UNSPECIFIED;
14
-
15
- type ResolveParams<T> = T extends Unspecified
16
- ? unknown
17
- : T extends BottomSheetPortalId
18
- ? BottomSheetPortalParams<T>
19
- : unknown;
20
-
21
- export interface UseBottomSheetStateReturn<T> {
11
+ export interface UseBottomSheetContextReturn<TParams> {
22
12
  bottomSheetState: BottomSheetState;
23
- params: ResolveParams<T>;
13
+ params: TParams;
24
14
  close: () => void;
15
+ /** @deprecated Use `close` instead */
25
16
  closeBottomSheet: () => void;
26
17
  }
27
18
 
28
- export function useBottomSheetState<
29
- T extends BottomSheetPortalId | Unspecified = Unspecified,
30
- >(): UseBottomSheetStateReturn<T> {
19
+ /** Without generic - params typed as unknown */
20
+ export function useBottomSheetContext(): UseBottomSheetContextReturn<unknown>;
21
+ /** With generic - params typed based on portal registry */
22
+ export function useBottomSheetContext<
23
+ T extends BottomSheetPortalId,
24
+ >(): UseBottomSheetContextReturn<BottomSheetPortalParams<T>>;
25
+ export function useBottomSheetContext<
26
+ T extends BottomSheetPortalId,
27
+ >(): UseBottomSheetContextReturn<BottomSheetPortalParams<T> | unknown> {
31
28
  const context = useMaybeBottomSheetContext();
32
29
 
33
30
  const bottomSheetState = useBottomSheetStore(
@@ -38,7 +35,7 @@ export function useBottomSheetState<
38
35
 
39
36
  if (!bottomSheetState) {
40
37
  throw new Error(
41
- 'useBottomSheetState must be used within a BottomSheetProvider'
38
+ 'useBottomSheetContext must be used within a BottomSheet component'
42
39
  );
43
40
  }
44
41
 
@@ -46,8 +43,13 @@ export function useBottomSheetState<
46
43
 
47
44
  return {
48
45
  bottomSheetState,
49
- params: bottomSheetState.params as ResolveParams<T>,
46
+ params: bottomSheetState.params as BottomSheetPortalParams<T>,
50
47
  close,
51
48
  closeBottomSheet: close,
52
49
  };
53
50
  }
51
+
52
+ /**
53
+ * @deprecated Use `useBottomSheetContext` instead
54
+ */
55
+ export const useBottomSheetState = useBottomSheetContext;
@@ -0,0 +1,25 @@
1
+ import {
2
+ useBottomSheetStore,
3
+ type BottomSheetStatus,
4
+ } from './bottomSheet.store';
5
+ import type { BottomSheetPortalId } from './portal.types';
6
+
7
+ export interface UseBottomSheetStatusReturn {
8
+ status: BottomSheetStatus | null;
9
+ isOpen: boolean;
10
+ }
11
+
12
+ export function useBottomSheetStatus(
13
+ id: BottomSheetPortalId
14
+ ): UseBottomSheetStatusReturn {
15
+ const status = useBottomSheetStore(
16
+ (state) => state.sheetsById[id]?.status ?? null
17
+ );
18
+
19
+ const isOpen = status === 'open' || status === 'opening';
20
+
21
+ return {
22
+ status,
23
+ isOpen,
24
+ };
25
+ }