@niibase/bottom-sheet-manager 1.3.0 → 1.4.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 (54) hide show
  1. package/README.md +204 -193
  2. package/lib/commonjs/index.js +9 -2
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/manager.js +56 -16
  5. package/lib/commonjs/manager.js.map +1 -1
  6. package/lib/commonjs/provider.js +41 -44
  7. package/lib/commonjs/provider.js.map +1 -1
  8. package/lib/commonjs/router/index.js +37 -7
  9. package/lib/commonjs/router/index.js.map +1 -1
  10. package/lib/commonjs/router/router.js.map +1 -1
  11. package/lib/commonjs/router/view.js +77 -220
  12. package/lib/commonjs/router/view.js.map +1 -1
  13. package/lib/commonjs/sheet.js +61 -85
  14. package/lib/commonjs/sheet.js.map +1 -1
  15. package/lib/module/index.js +2 -2
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/manager.js +56 -16
  18. package/lib/module/manager.js.map +1 -1
  19. package/lib/module/provider.js +39 -42
  20. package/lib/module/provider.js.map +1 -1
  21. package/lib/module/router/index.js +39 -8
  22. package/lib/module/router/index.js.map +1 -1
  23. package/lib/module/router/router.js.map +1 -1
  24. package/lib/module/router/view.js +76 -220
  25. package/lib/module/router/view.js.map +1 -1
  26. package/lib/module/sheet.js +63 -87
  27. package/lib/module/sheet.js.map +1 -1
  28. package/lib/typescript/index.d.ts +2 -2
  29. package/lib/typescript/index.d.ts.map +1 -1
  30. package/lib/typescript/manager.d.ts +16 -0
  31. package/lib/typescript/manager.d.ts.map +1 -1
  32. package/lib/typescript/provider.d.ts +10 -23
  33. package/lib/typescript/provider.d.ts.map +1 -1
  34. package/lib/typescript/router/index.d.ts +21 -7
  35. package/lib/typescript/router/index.d.ts.map +1 -1
  36. package/lib/typescript/router/router.d.ts.map +1 -1
  37. package/lib/typescript/router/types.d.ts +75 -61
  38. package/lib/typescript/router/types.d.ts.map +1 -1
  39. package/lib/typescript/router/view.d.ts +3 -3
  40. package/lib/typescript/router/view.d.ts.map +1 -1
  41. package/lib/typescript/sheet.d.ts +1 -1
  42. package/lib/typescript/sheet.d.ts.map +1 -1
  43. package/lib/typescript/types.d.ts +32 -15
  44. package/lib/typescript/types.d.ts.map +1 -1
  45. package/package.json +14 -15
  46. package/src/index.ts +7 -7
  47. package/src/manager.ts +66 -22
  48. package/src/provider.tsx +72 -53
  49. package/src/router/index.tsx +46 -9
  50. package/src/router/router.ts +6 -2
  51. package/src/router/types.ts +109 -91
  52. package/src/router/view.tsx +86 -308
  53. package/src/sheet.tsx +111 -123
  54. package/src/types.ts +146 -133
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { BottomSheetProps as RNBottomSheetProps } from "@gorhom/bottom-sheet";
2
2
  import type { WithSpringConfig, WithTimingConfig } from "react-native-reanimated";
3
+ import { StatusBarStyle } from "react-native";
3
4
  import React from "react";
4
5
 
5
6
  export interface Sheets {}
@@ -11,14 +12,14 @@ export type SheetReturnValue<Id extends SheetIds> = Sheets[Id]["returnValue"];
11
12
  type AnimationConfigs = WithSpringConfig | WithTimingConfig;
12
13
 
13
14
  export interface SheetProps<Id extends SheetIds = SheetIds> {
14
- readonly id: SheetID<Id>;
15
- readonly payload: SheetPayload<Id>;
16
- readonly context: string;
15
+ readonly id: SheetID<Id>;
16
+ readonly payload: SheetPayload<Id>;
17
+ readonly context: string;
17
18
  }
18
19
 
19
20
  export interface SheetDefinition<Payload = never, ReturnValue = never> {
20
- payload: Payload;
21
- returnValue: ReturnValue;
21
+ payload: Payload;
22
+ returnValue: ReturnValue;
22
23
  }
23
24
 
24
25
  /**
@@ -30,139 +31,151 @@ export interface SheetDefinition<Payload = never, ReturnValue = never> {
30
31
  * - `replace`: Closes current sheet and opens new one. Previous sheet is
31
32
  * removed from stack (not restored on close).
32
33
  *
33
- * - `push`: (experimental) Stacks new sheet on top. Previous sheet remains visible underneath.
34
+ * - `push`: Stacks new sheet on top. Previous sheet remains visible underneath.
34
35
  */
35
36
  export type StackBehavior = "switch" | "replace" | "push";
36
37
 
38
+ export type SheetProviderProps = React.PropsWithChildren<{
39
+ context?: string;
40
+ /** @default default */
41
+ statusBar?: StatusBarStyle;
42
+ scaleConfig?: {
43
+ /** Scale factor when sheet is open (default: 0.92) */
44
+ scale?: number;
45
+ /** Vertical translation when sheet is open (default: 5) */
46
+ translateY?: number;
47
+ /** Border radius when sheet is open (default: 24) */
48
+ borderRadius?: number;
49
+ /** Animation config - timing or spring (default: timing with 300ms duration) */
50
+ animation?:
51
+ | { type: "timing"; config?: WithTimingConfig }
52
+ | { type: "spring"; config?: WithSpringConfig };
53
+ };
54
+ }>;
55
+
37
56
  export interface BottomSheetInstance<Id extends SheetIds = SheetIds> {
38
- /**
39
- * Close the bottom sheet.
40
- * @param args
41
- */
42
- readonly close: (
43
- ...args: SheetReturnValue<Id> extends never
44
- ? [
45
- options?: {
46
- /**
47
- * Snap animation configs.
48
- */
49
- animationConfigs?: AnimationConfigs;
50
- },
51
- ]
52
- : [
53
- options: {
54
- /**
55
- * Return some data to the caller on closing the `BottomSheet`.
56
- */
57
- value: SheetReturnValue<Id>;
58
-
59
- /**
60
- * Snap animation configs.
61
- */
62
- animationConfigs?: AnimationConfigs;
63
- },
64
- ]
65
- ) => void;
66
-
67
- /**
68
- * Snap to the maximum provided point from `snapPoints`.
69
- * @param animationConfigs Snap animation configs.
70
- */
71
- readonly expand: (animationConfigs?: AnimationConfigs) => void;
72
-
73
- /**
74
- * Snap to the minimum provided point from `snapPoints`.
75
- * @param animationConfigs Snap animation configs.
76
- */
77
- readonly collapse: (animationConfigs?: AnimationConfigs) => void;
78
-
79
- /**
80
- * Snap to one of the provided points from `snapPoints`.
81
- * @param index Snap point index.
82
- * @param animationConfigs Snap animation configs.
83
- */
84
- readonly snapToIndex: (index: number, animationConfigs?: AnimationConfigs) => void;
85
-
86
- /**
87
- * Snap to a position out of provided `snapPoints`.
88
- * @param position Position in pixel or percentage.
89
- * @param animationConfigs Snap animation configs.
90
- */
91
- readonly snapToPosition: (
92
- position: string | number,
93
- animationConfigs?: AnimationConfigs,
94
- ) => void;
57
+ /**
58
+ * Close the bottom sheet.
59
+ * @param args
60
+ */
61
+ readonly close: (
62
+ ...args: SheetReturnValue<Id> extends never
63
+ ? [
64
+ options?: {
65
+ /**
66
+ * Snap animation configs.
67
+ */
68
+ animationConfigs?: AnimationConfigs;
69
+ },
70
+ ]
71
+ : [
72
+ options: {
73
+ /**
74
+ * Return some data to the caller on closing the `BottomSheet`.
75
+ */
76
+ value: SheetReturnValue<Id>;
77
+
78
+ /**
79
+ * Snap animation configs.
80
+ */
81
+ animationConfigs?: AnimationConfigs;
82
+ },
83
+ ]
84
+ ) => void;
85
+
86
+ /**
87
+ * Snap to the maximum provided point from `snapPoints`.
88
+ * @param animationConfigs Snap animation configs.
89
+ */
90
+ readonly expand: (animationConfigs?: AnimationConfigs) => void;
91
+
92
+ /**
93
+ * Snap to the minimum provided point from `snapPoints`.
94
+ * @param animationConfigs Snap animation configs.
95
+ */
96
+ readonly collapse: (animationConfigs?: AnimationConfigs) => void;
97
+
98
+ /**
99
+ * Snap to one of the provided points from `snapPoints`.
100
+ * @param index Snap point index.
101
+ * @param animationConfigs Snap animation configs.
102
+ */
103
+ readonly snapToIndex: (index: number, animationConfigs?: AnimationConfigs) => void;
104
+
105
+ /**
106
+ * Snap to a position out of provided `snapPoints`.
107
+ * @param position Position in pixel or percentage.
108
+ * @param animationConfigs Snap animation configs.
109
+ */
110
+ readonly snapToPosition: (
111
+ position: string | number,
112
+ animationConfigs?: AnimationConfigs,
113
+ ) => void;
95
114
  }
96
115
 
97
- export type BottomSheetProps = Omit<
98
- RNBottomSheetProps,
99
- "children" | "onClose"
116
+ export type BottomSheetProps<Id extends SheetIds = SheetIds> = Omit<
117
+ RNBottomSheetProps,
118
+ "children" | "onClose"
100
119
  > & {
101
- /**
102
- * ID of the `BottomSheet`.
103
- */
104
- id?: SheetID<SheetIds>;
105
-
106
- /**
107
- * Content of the `BottomSheet`.
108
- */
109
- children: React.ReactNode;
110
-
111
- /**
112
- * When set to true, `BottomSheet` is closed when the hardware back button is pressed.
113
- * @default true
114
- */
115
- hardwareBackPressToClose?: boolean;
116
-
117
- /**
118
- * Callback when the sheet close.
119
- *
120
- * @type () => any;
121
- * @returns The data returned by the sheet to be returned when closed.
122
- */
123
- onClose?: (data?: unknown) => unknown;
124
-
125
- /**
126
- * Event called before sheets is visible.
127
- * @param data Payload of the sheet if any.
128
- * @type () => void;
129
- */
130
- onBeforeShow?: (data?: unknown) => void;
131
-
132
- /**
133
- * Can click through the sheet to the underlying view.
134
- * @default false
135
- */
136
- clickThrough?: boolean;
137
-
138
- /**
139
- * Opacity of the sheet's overlay.
140
- * @default 0.45
141
- */
142
- opacity?: number;
143
-
144
- /**
145
- * Defines the stack behavior when sheets are opened.
146
- *
147
- * - `switch`: (default) Dismisses the current sheet before showing the new one.
148
- * - `replace`: Swaps the current sheet's content with smooth crossfade animation.
149
- * - `push`: (experimental) Pushes new sheet on top, creating a navigable stack.
150
- *
151
- * @default "switch"
152
- */
153
- stackBehavior?: StackBehavior;
154
-
155
- /**
156
- * Whether the bottom sheet is an iOS 18 modal sheet type of animation.
157
- * When enabled at snap point 90%, the content behind the sheet scales down and gets a
158
- * border radius, similar to iOS 18 system sheets.
159
- * @default false
160
- */
161
- iosModalSheetTypeOfAnimation?: boolean;
162
-
163
- className?: string;
164
- handleIndicatorClassName?: string;
165
- backgroundClassName?: string;
166
- containerClassName?: string;
167
- handleClassName?: string;
120
+ /**
121
+ * ID of the `BottomSheet`.
122
+ */
123
+ id?: SheetID<Id>;
124
+
125
+ /**
126
+ * Content of the `BottomSheet`.
127
+ */
128
+ children: React.ReactNode;
129
+
130
+ /**
131
+ * When set to true, `BottomSheet` is closed when the hardware back button is pressed.
132
+ * @default true
133
+ */
134
+ hardwareBackPressToClose?: boolean;
135
+
136
+ /**
137
+ * Callback when the sheet closes. Return a value to override the close data
138
+ * forwarded to `SheetManager.show()` callers.
139
+ *
140
+ * @returns Optionally return a new value to pass back to the caller.
141
+ */
142
+ onClose?: (data?: SheetReturnValue<Id>) => SheetReturnValue<Id> | void;
143
+
144
+ /**
145
+ * Event called before sheets is visible.
146
+ * @param data Payload of the sheet if any.
147
+ * @type () => void;
148
+ */
149
+ onBeforeShow?: (data?: SheetPayload<Id>) => void;
150
+
151
+ /**
152
+ * Can click through the sheet to the underlying view.
153
+ * @default false
154
+ */
155
+ passThrough?: boolean;
156
+
157
+ /**
158
+ * Opacity of the sheet's overlay.
159
+ * @default 0.45
160
+ */
161
+ opacity?: number;
162
+
163
+ /**
164
+ * Defines the stack behavior when sheets are opened.
165
+ *
166
+ * - `switch`: (default) Dismisses the current sheet before showing the new one.
167
+ * - `replace`: Swaps the current sheet's content with smooth crossfade animation.
168
+ * - `push`: Pushes new sheet on top, creating a navigable stack.
169
+ *
170
+ * @default "switch"
171
+ */
172
+ stackBehavior?: StackBehavior;
173
+
174
+ /**
175
+ * Whether the bottom sheet is an iOS 18 modal sheet type of animation.
176
+ * When enabled at snap point 90%, the content behind the sheet scales down and gets a
177
+ * border radius, similar to iOS 18 system sheets.
178
+ * @default false
179
+ */
180
+ iosModalSheetTypeOfAnimation?: boolean;
168
181
  };