react-native-bottom-sheet-stack 1.4.3 → 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 (95) hide show
  1. package/README.md +7 -3
  2. package/lib/commonjs/BottomSheetHost.js +135 -105
  3. package/lib/commonjs/BottomSheetHost.js.map +1 -1
  4. package/lib/commonjs/BottomSheetManaged.js +1 -1
  5. package/lib/commonjs/BottomSheetManaged.js.map +1 -1
  6. package/lib/commonjs/BottomSheetPortal.js +2 -3
  7. package/lib/commonjs/BottomSheetPortal.js.map +1 -1
  8. package/lib/commonjs/BottomSheetScaleView.js +23 -14
  9. package/lib/commonjs/BottomSheetScaleView.js.map +1 -1
  10. package/lib/commonjs/bottomSheet.store.js +19 -55
  11. package/lib/commonjs/bottomSheet.store.js.map +1 -1
  12. package/lib/commonjs/bottomSheetCoordinator.js +2 -2
  13. package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
  14. package/lib/commonjs/index.js +17 -4
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/refsMap.js +13 -2
  17. package/lib/commonjs/refsMap.js.map +1 -1
  18. package/lib/commonjs/useBottomSheetControl.js +57 -65
  19. package/lib/commonjs/useBottomSheetControl.js.map +1 -1
  20. package/lib/commonjs/useBottomSheetManager.js +33 -48
  21. package/lib/commonjs/useBottomSheetManager.js.map +1 -1
  22. package/lib/commonjs/useBottomSheetState.js +12 -4
  23. package/lib/commonjs/useBottomSheetState.js.map +1 -1
  24. package/lib/commonjs/useBottomSheetStatus.js +35 -0
  25. package/lib/commonjs/useBottomSheetStatus.js.map +1 -0
  26. package/lib/commonjs/useScaleAnimation.js +15 -10
  27. package/lib/commonjs/useScaleAnimation.js.map +1 -1
  28. package/lib/typescript/example/src/App.d.ts.map +1 -1
  29. package/lib/typescript/example/src/components/Badge.d.ts +9 -0
  30. package/lib/typescript/example/src/components/Badge.d.ts.map +1 -0
  31. package/lib/typescript/example/src/components/Button.d.ts +14 -0
  32. package/lib/typescript/example/src/components/Button.d.ts.map +1 -0
  33. package/lib/typescript/example/src/components/DemoCard.d.ts +14 -0
  34. package/lib/typescript/example/src/components/DemoCard.d.ts.map +1 -0
  35. package/lib/typescript/example/src/components/Sheet.d.ts +14 -0
  36. package/lib/typescript/example/src/components/Sheet.d.ts.map +1 -0
  37. package/lib/typescript/example/src/components/index.d.ts +5 -0
  38. package/lib/typescript/example/src/components/index.d.ts.map +1 -0
  39. package/lib/typescript/example/src/context/UserContext.d.ts +13 -0
  40. package/lib/typescript/example/src/context/UserContext.d.ts.map +1 -0
  41. package/lib/typescript/example/src/context/index.d.ts +2 -0
  42. package/lib/typescript/example/src/context/index.d.ts.map +1 -0
  43. package/lib/typescript/example/src/screens/HomeScreen.d.ts +2 -0
  44. package/lib/typescript/example/src/screens/HomeScreen.d.ts.map +1 -0
  45. package/lib/typescript/example/src/screens/index.d.ts +2 -0
  46. package/lib/typescript/example/src/screens/index.d.ts.map +1 -0
  47. package/lib/typescript/example/src/sheets/ContextSheets.d.ts +10 -0
  48. package/lib/typescript/example/src/sheets/ContextSheets.d.ts.map +1 -0
  49. package/lib/typescript/example/src/sheets/DynamicContentSheet.d.ts +3 -0
  50. package/lib/typescript/example/src/sheets/DynamicContentSheet.d.ts.map +1 -0
  51. package/lib/typescript/example/src/sheets/NavigationSheets.d.ts +6 -0
  52. package/lib/typescript/example/src/sheets/NavigationSheets.d.ts.map +1 -0
  53. package/lib/typescript/example/src/sheets/NestedScaleSheets.d.ts +5 -0
  54. package/lib/typescript/example/src/sheets/NestedScaleSheets.d.ts.map +1 -0
  55. package/lib/typescript/example/src/sheets/PortalModeSheets.d.ts +4 -0
  56. package/lib/typescript/example/src/sheets/PortalModeSheets.d.ts.map +1 -0
  57. package/lib/typescript/example/src/sheets/index.d.ts +6 -0
  58. package/lib/typescript/example/src/sheets/index.d.ts.map +1 -0
  59. package/lib/typescript/example/src/styles/index.d.ts +2 -0
  60. package/lib/typescript/example/src/styles/index.d.ts.map +1 -0
  61. package/lib/typescript/example/src/styles/theme.d.ts +164 -0
  62. package/lib/typescript/example/src/styles/theme.d.ts.map +1 -0
  63. package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
  64. package/lib/typescript/src/BottomSheetPortal.d.ts.map +1 -1
  65. package/lib/typescript/src/BottomSheetScaleView.d.ts.map +1 -1
  66. package/lib/typescript/src/bottomSheet.store.d.ts +2 -8
  67. package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
  68. package/lib/typescript/src/index.d.ts +8 -6
  69. package/lib/typescript/src/index.d.ts.map +1 -1
  70. package/lib/typescript/src/refsMap.d.ts +6 -1
  71. package/lib/typescript/src/refsMap.d.ts.map +1 -1
  72. package/lib/typescript/src/useBottomSheetControl.d.ts +7 -4
  73. package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
  74. package/lib/typescript/src/useBottomSheetManager.d.ts +10 -17
  75. package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
  76. package/lib/typescript/src/useBottomSheetState.d.ts +11 -7
  77. package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
  78. package/lib/typescript/src/useBottomSheetStatus.d.ts +8 -0
  79. package/lib/typescript/src/useBottomSheetStatus.d.ts.map +1 -0
  80. package/lib/typescript/src/useScaleAnimation.d.ts +4 -1
  81. package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/BottomSheetHost.tsx +12 -14
  84. package/src/BottomSheetManaged.tsx +2 -2
  85. package/src/BottomSheetPortal.tsx +6 -5
  86. package/src/BottomSheetScaleView.tsx +2 -3
  87. package/src/bottomSheet.store.ts +28 -65
  88. package/src/bottomSheetCoordinator.ts +3 -3
  89. package/src/index.tsx +27 -6
  90. package/src/refsMap.ts +16 -4
  91. package/src/useBottomSheetControl.ts +22 -18
  92. package/src/useBottomSheetManager.tsx +25 -34
  93. package/src/useBottomSheetState.ts +19 -17
  94. package/src/useBottomSheetStatus.ts +25 -0
  95. package/src/useScaleAnimation.ts +7 -2
@@ -2,25 +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 {
13
- pushBottomSheet,
14
- replaceBottomSheet,
15
- switchBottomSheet,
16
- startClosing,
17
- storeClearAll,
18
- } = useBottomSheetStore(
12
+ const { storeOpen, startClosing, storeClearGroup } = useBottomSheetStore(
19
13
  (store) => ({
20
- storeClearAll: store.clearAll,
21
- replaceBottomSheet: store.replace,
22
- pushBottomSheet: store.push,
23
- switchBottomSheet: store.switch,
14
+ storeOpen: store.open,
15
+ storeClearGroup: store.clearGroup,
24
16
  startClosing: store.startClosing,
25
17
  }),
26
18
  shallow
@@ -41,25 +33,21 @@ export const useBottomSheetManager = () => {
41
33
  const id = options.id || Math.random().toString(36);
42
34
  const ref = React.createRef<BottomSheetMethods>();
43
35
 
44
- sheetRefs[id] = ref;
36
+ setSheetRef(id, ref);
45
37
 
46
- // @ts-ignore
47
- const contentWithRef = React.cloneElement(content, { ref });
38
+ const contentWithRef = React.cloneElement(content, {
39
+ ref,
40
+ } as { ref: typeof ref });
48
41
 
49
- const sheetData = {
50
- id,
51
- groupId,
52
- content: contentWithRef,
53
- scaleBackground: options.scaleBackground,
54
- };
55
-
56
- if (options.mode === 'replace') {
57
- replaceBottomSheet(sheetData);
58
- } else if (options.mode === 'switch') {
59
- switchBottomSheet(sheetData);
60
- } else {
61
- pushBottomSheet(sheetData);
62
- }
42
+ storeOpen(
43
+ {
44
+ id,
45
+ groupId,
46
+ content: contentWithRef,
47
+ scaleBackground: options.scaleBackground,
48
+ },
49
+ options.mode
50
+ );
63
51
 
64
52
  return id;
65
53
  };
@@ -68,15 +56,18 @@ export const useBottomSheetManager = () => {
68
56
  startClosing(id);
69
57
  };
70
58
 
71
- const clearAll = () => {
72
- storeClearAll();
59
+ const clear = () => {
60
+ const groupId = bottomSheetManagerContext?.groupId || 'default';
61
+ storeClearGroup(groupId);
73
62
  };
74
63
 
75
64
  return {
76
- clearAll,
65
+ open: openBottomSheet,
77
66
  close,
67
+ clear,
68
+ /** @deprecated Use `open` instead */
78
69
  openBottomSheet,
79
- pushBottomSheet,
80
- replaceBottomSheet,
70
+ /** @deprecated Use `clear` instead */
71
+ clearAll: clear,
81
72
  };
82
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
+ }
@@ -78,7 +78,12 @@ export function useScaleDepth(groupId: string, sheetId?: string): number {
78
78
  * Returns animated style for scale effect based on depth.
79
79
  * Uses power scaling: scale^depth for cascading effect.
80
80
  */
81
- export function useScaleAnimatedStyle(depth: number, config?: ScaleConfig) {
81
+ export function useScaleAnimatedStyle(
82
+ { groupId, id }: { groupId: string; id?: string },
83
+ config?: ScaleConfig
84
+ ) {
85
+ const scaleDepth = useScaleDepth(groupId, id);
86
+
82
87
  const {
83
88
  scale = DEFAULT_CONFIG.scale,
84
89
  translateY = DEFAULT_CONFIG.translateY,
@@ -87,7 +92,7 @@ export function useScaleAnimatedStyle(depth: number, config?: ScaleConfig) {
87
92
  } = config ?? {};
88
93
 
89
94
  const progress = useDerivedValue(() => {
90
- return withTiming(depth, { duration });
95
+ return withTiming(scaleDepth, { duration });
91
96
  });
92
97
 
93
98
  return useAnimatedStyle(() => {