@niibase/bottom-sheet-manager 1.1.0 → 1.3.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.
- package/README.md +372 -38
- package/lib/commonjs/events.js +100 -15
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/manager.js +107 -29
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/provider.js +69 -28
- package/lib/commonjs/provider.js.map +1 -1
- package/lib/commonjs/router/index.js +50 -21
- package/lib/commonjs/router/index.js.map +1 -1
- package/lib/commonjs/router/router.js +137 -12
- package/lib/commonjs/router/router.js.map +1 -1
- package/lib/commonjs/router/view.js +194 -84
- package/lib/commonjs/router/view.js.map +1 -1
- package/lib/commonjs/sheet.js +125 -76
- package/lib/commonjs/sheet.js.map +1 -1
- package/lib/module/events.js +100 -15
- package/lib/module/events.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/manager.js +108 -29
- package/lib/module/manager.js.map +1 -1
- package/lib/module/provider.js +65 -25
- package/lib/module/provider.js.map +1 -1
- package/lib/module/router/index.js +34 -18
- package/lib/module/router/index.js.map +1 -1
- package/lib/module/router/router.js +135 -11
- package/lib/module/router/router.js.map +1 -1
- package/lib/module/router/view.js +194 -84
- package/lib/module/router/view.js.map +1 -1
- package/lib/module/sheet.js +127 -78
- package/lib/module/sheet.js.map +1 -1
- package/lib/typescript/events.d.ts +46 -12
- package/lib/typescript/events.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/manager.d.ts +57 -7
- package/lib/typescript/manager.d.ts.map +1 -1
- package/lib/typescript/provider.d.ts +22 -3
- package/lib/typescript/provider.d.ts.map +1 -1
- package/lib/typescript/router/index.d.ts +33 -17
- package/lib/typescript/router/index.d.ts.map +1 -1
- package/lib/typescript/router/router.d.ts +44 -5
- package/lib/typescript/router/router.d.ts.map +1 -1
- package/lib/typescript/router/types.d.ts +113 -17
- package/lib/typescript/router/types.d.ts.map +1 -1
- package/lib/typescript/router/view.d.ts +1 -1
- package/lib/typescript/router/view.d.ts.map +1 -1
- package/lib/typescript/sheet.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +27 -12
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/events.ts +118 -27
- package/src/index.ts +6 -5
- package/src/manager.ts +156 -33
- package/src/provider.tsx +98 -44
- package/src/router/index.tsx +38 -31
- package/src/router/router.ts +184 -15
- package/src/router/types.ts +119 -22
- package/src/router/view.tsx +252 -132
- package/src/sheet.tsx +176 -95
- package/src/types.ts +144 -129
package/lib/module/manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { eventManager } from "./events";
|
|
2
1
|
import { providerRegistryStack, sheetsRegistry } from "./provider";
|
|
2
|
+
import { eventManager } from "./events";
|
|
3
|
+
|
|
3
4
|
// Array of all the ids of Sheets currently rendered in the app.
|
|
4
5
|
const ids = [];
|
|
5
6
|
const keys = [];
|
|
@@ -7,12 +8,12 @@ const refs = {};
|
|
|
7
8
|
const DEFAULT_Z_INDEX = 999;
|
|
8
9
|
const makeKey = (id, context) => `${id}:${context}`;
|
|
9
10
|
export const PrivateManager = {
|
|
10
|
-
//
|
|
11
|
+
// Stack of sheet history for restoration when sheets are closed
|
|
11
12
|
history: [],
|
|
12
13
|
context(options) {
|
|
13
14
|
if (!options) options = {};
|
|
14
15
|
if (!options?.context) {
|
|
15
|
-
// If no context is provided, use
|
|
16
|
+
// If no context is provided, use the current top-most context
|
|
16
17
|
// to render the sheet.
|
|
17
18
|
for (const context of providerRegistryStack.slice().reverse()) {
|
|
18
19
|
// We only automatically select nested sheet providers.
|
|
@@ -27,10 +28,11 @@ export const PrivateManager = {
|
|
|
27
28
|
registerRef: (id, context, instance) => {
|
|
28
29
|
const key = makeKey(id, context);
|
|
29
30
|
refs[key] = instance;
|
|
30
|
-
keys.
|
|
31
|
+
if (!keys.includes(key)) {
|
|
32
|
+
keys.push(key);
|
|
33
|
+
}
|
|
31
34
|
},
|
|
32
35
|
/**
|
|
33
|
-
*
|
|
34
36
|
* Get internal ref of a sheet by the given id.
|
|
35
37
|
*
|
|
36
38
|
* @param id Id of the sheet
|
|
@@ -38,8 +40,8 @@ export const PrivateManager = {
|
|
|
38
40
|
*/
|
|
39
41
|
get: (id, context) => {
|
|
40
42
|
if (!context) {
|
|
41
|
-
for (
|
|
42
|
-
for (
|
|
43
|
+
for (const ctx of providerRegistryStack.slice().reverse()) {
|
|
44
|
+
for (const _id in sheetsRegistry[ctx]) {
|
|
43
45
|
if (_id === id) {
|
|
44
46
|
context = ctx;
|
|
45
47
|
break;
|
|
@@ -50,25 +52,52 @@ export const PrivateManager = {
|
|
|
50
52
|
return refs[makeKey(id, context)];
|
|
51
53
|
},
|
|
52
54
|
add: (id, context) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const key = makeKey(id, context);
|
|
56
|
+
if (!ids.includes(key)) {
|
|
57
|
+
ids.push(key);
|
|
55
58
|
}
|
|
56
59
|
},
|
|
57
60
|
remove: (id, context) => {
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const key = makeKey(id, context);
|
|
62
|
+
const index = ids.indexOf(key);
|
|
63
|
+
if (index > -1) {
|
|
64
|
+
ids.splice(index, 1);
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
67
|
zIndex: (id, context = "global") => {
|
|
63
68
|
const index = keys.indexOf(makeKey(id, context));
|
|
64
69
|
return index > -1 ? DEFAULT_Z_INDEX + index + 1 : DEFAULT_Z_INDEX;
|
|
65
70
|
},
|
|
66
|
-
stack: () => ids.map(id => {
|
|
71
|
+
stack: () => ids.map(id => ({
|
|
72
|
+
id: id.split(":")[0],
|
|
73
|
+
context: id.split(":")?.[1] || "global"
|
|
74
|
+
})),
|
|
75
|
+
/**
|
|
76
|
+
* Get the top-most sheet in the stack
|
|
77
|
+
*/
|
|
78
|
+
topSheet: () => {
|
|
79
|
+
if (ids.length === 0) return null;
|
|
80
|
+
const topId = ids[ids.length - 1];
|
|
67
81
|
return {
|
|
68
|
-
id:
|
|
69
|
-
context:
|
|
82
|
+
id: topId.split(":")[0],
|
|
83
|
+
context: topId.split(":")?.[1] || "global"
|
|
70
84
|
};
|
|
71
|
-
}
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Check if a sheet is currently visible
|
|
88
|
+
*/
|
|
89
|
+
isSheetVisible: (id, context) => {
|
|
90
|
+
if (context) {
|
|
91
|
+
return ids.includes(makeKey(id, context));
|
|
92
|
+
}
|
|
93
|
+
return ids.some(key => key.startsWith(`${id}:`));
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Clear all history entries
|
|
97
|
+
*/
|
|
98
|
+
clearHistory: () => {
|
|
99
|
+
PrivateManager.history = [];
|
|
100
|
+
}
|
|
72
101
|
};
|
|
73
102
|
class _SheetManager {
|
|
74
103
|
/**
|
|
@@ -83,30 +112,38 @@ class _SheetManager {
|
|
|
83
112
|
...options,
|
|
84
113
|
id: id
|
|
85
114
|
});
|
|
86
|
-
const
|
|
115
|
+
const behavior = options?.stackBehavior ?? "switch";
|
|
116
|
+
const handler = (data, context = "global", _reopened, _behavior) => {
|
|
87
117
|
if (context !== "global" && currentContext && currentContext !== context) return;
|
|
88
118
|
options?.onClose?.(data);
|
|
89
119
|
sub?.unsubscribe();
|
|
90
120
|
resolve(data);
|
|
91
121
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
122
|
+
const sub = eventManager.subscribe(`onclose_${id}`, handler);
|
|
123
|
+
|
|
124
|
+
// Handle existing sheets based on stack behavior
|
|
125
|
+
const currentStack = PrivateManager.stack();
|
|
126
|
+
if (currentStack.length > 0) {
|
|
127
|
+
currentStack.forEach(({
|
|
128
|
+
id: sheetId,
|
|
129
|
+
context
|
|
130
|
+
}) => {
|
|
131
|
+
eventManager.publish(`hide_${sheetId}`, undefined, context, true, behavior);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
99
134
|
|
|
100
135
|
// Check if the sheet is registered with any `SheetProviders`.
|
|
101
136
|
let isRegisteredWithSheetProvider = false;
|
|
102
|
-
for (
|
|
103
|
-
for (
|
|
137
|
+
for (const ctx in sheetsRegistry) {
|
|
138
|
+
for (const _id in sheetsRegistry[ctx]) {
|
|
104
139
|
if (_id === id) {
|
|
105
140
|
isRegisteredWithSheetProvider = true;
|
|
141
|
+
break;
|
|
106
142
|
}
|
|
107
143
|
}
|
|
144
|
+
if (isRegisteredWithSheetProvider) break;
|
|
108
145
|
}
|
|
109
|
-
eventManager.publish(isRegisteredWithSheetProvider ? `show_wrap_${id}` : `show_${id}`, options?.payload, currentContext || "global");
|
|
146
|
+
eventManager.publish(isRegisteredWithSheetProvider ? `show_wrap_${id}` : `show_${id}`, options?.payload, currentContext || "global", false, behavior);
|
|
110
147
|
});
|
|
111
148
|
}
|
|
112
149
|
|
|
@@ -114,10 +151,10 @@ class _SheetManager {
|
|
|
114
151
|
* An async hide function. This is useful when you want to show one Sheet after closing another.
|
|
115
152
|
*
|
|
116
153
|
* @param id id of the Sheet to show
|
|
117
|
-
* @param
|
|
154
|
+
* @param options
|
|
118
155
|
*/
|
|
119
156
|
async hide(id, options) {
|
|
120
|
-
|
|
157
|
+
const currentContext = PrivateManager.context({
|
|
121
158
|
...options,
|
|
122
159
|
id: id
|
|
123
160
|
});
|
|
@@ -137,7 +174,7 @@ class _SheetManager {
|
|
|
137
174
|
sub?.unsubscribe();
|
|
138
175
|
resolve(data);
|
|
139
176
|
};
|
|
140
|
-
|
|
177
|
+
const sub = eventManager.subscribe(`onclose_${id}`, hideHandler);
|
|
141
178
|
eventManager.publish(isRegisteredWithSheetProvider ? `hide_wrap_${id}` : `hide_${id}`, options?.payload, !isRegisteredWithSheetProvider ? "global" : currentContext);
|
|
142
179
|
});
|
|
143
180
|
}
|
|
@@ -148,6 +185,8 @@ class _SheetManager {
|
|
|
148
185
|
* @param id Hide all sheets for the specific id.
|
|
149
186
|
*/
|
|
150
187
|
hideAll(id) {
|
|
188
|
+
// Clear history when hiding all sheets
|
|
189
|
+
PrivateManager.clearHistory();
|
|
151
190
|
PrivateManager.stack().forEach(({
|
|
152
191
|
id: _id,
|
|
153
192
|
context
|
|
@@ -156,6 +195,46 @@ class _SheetManager {
|
|
|
156
195
|
eventManager.publish(`hide_${_id}`, undefined, context);
|
|
157
196
|
});
|
|
158
197
|
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Replace the current sheet with a new one using crossfade animation.
|
|
201
|
+
* This is a convenience method for show() with stackBehavior: 'replace'.
|
|
202
|
+
*/
|
|
203
|
+
async replace(id, options) {
|
|
204
|
+
return this.show(id, {
|
|
205
|
+
...options,
|
|
206
|
+
stackBehavior: "replace"
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Push a new sheet on top of the current one, creating a stack.
|
|
212
|
+
* This is a convenience method for show() with stackBehavior: 'push'.
|
|
213
|
+
*/
|
|
214
|
+
async push(id, options) {
|
|
215
|
+
return this.show(id, {
|
|
216
|
+
...options,
|
|
217
|
+
stackBehavior: "push"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Pop the top sheet from the stack and restore the previous one.
|
|
223
|
+
* Only works when sheets were opened with stackBehavior: 'push'.
|
|
224
|
+
*/
|
|
225
|
+
pop() {
|
|
226
|
+
const topSheet = PrivateManager.topSheet();
|
|
227
|
+
if (topSheet) {
|
|
228
|
+
eventManager.publish(`hide_${topSheet.id}`, undefined, topSheet.context);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Check if a specific sheet is currently visible.
|
|
234
|
+
*/
|
|
235
|
+
isVisible(id, context) {
|
|
236
|
+
return PrivateManager.isSheetVisible(id, context);
|
|
237
|
+
}
|
|
159
238
|
}
|
|
160
239
|
|
|
161
240
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["providerRegistryStack","sheetsRegistry","eventManager","ids","keys","refs","DEFAULT_Z_INDEX","makeKey","id","context","PrivateManager","history","options","slice","reverse","startsWith","includes","registerRef","instance","key","push","get","ctx","_id","add","remove","index","indexOf","splice","zIndex","stack","map","split","topSheet","length","topId","isSheetVisible","some","clearHistory","_SheetManager","show","Promise","resolve","currentContext","behavior","stackBehavior","handler","data","_reopened","_behavior","onClose","sub","unsubscribe","subscribe","currentStack","forEach","sheetId","publish","undefined","isRegisteredWithSheetProvider","payload","hide","hideHandler","hideAll","replace","pop","isVisible","SheetManager"],"sourceRoot":"../../src","sources":["manager.ts"],"mappings":"AAGA,SAASA,qBAAqB,EAAEC,cAAc,QAAQ,YAAY;AAClE,SAASC,YAAY,QAAQ,UAAU;;AAEvC;AACA,MAAMC,GAAa,GAAG,EAAE;AACxB,MAAMC,IAAc,GAAG,EAAE;AACzB,MAAMC,IAAwD,GAAG,CAAC,CAAC;AACnE,MAAMC,eAAe,GAAG,GAAG;AAE3B,MAAMC,OAAO,GAAGA,CAACC,EAAU,EAAEC,OAAe,KAAK,GAAGD,EAAE,IAAIC,OAAO,EAAE;AAQnE,OAAO,MAAMC,cAAc,GAAG;EAC1B;EACAC,OAAO,EAAE,EAAoB;EAE7BF,OAAOA,CAACG,OAA2C,EAAE;IACjD,IAAI,CAACA,OAAO,EAAEA,OAAO,GAAG,CAAC,CAAC;IAC1B,IAAI,CAACA,OAAO,EAAEH,OAAO,EAAE;MACnB;MACA;MACA,KAAK,MAAMA,OAAO,IAAIT,qBAAqB,CAACa,KAAK,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,EAAE;QAC3D;QACA,IACIL,OAAO,CAACM,UAAU,CAAC,SAAS,CAAC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,GAAGA,CAAA,EAAS;IACR,MAAMhC,QAAQ,GAAGvB,cAAc,CAACuB,QAAQ,CAAC,CAAC;IAC1C,IAAIA,QAAQ,EAAE;MACV/B,YAAY,CAACuD,OAAO,CAAC,QAAQxB,QAAQ,CAACzB,EAAE,EAAE,EAAEkD,SAAS,EAAEzB,QAAQ,CAACxB,OAAO,CAAC;IAC5E;EACJ;;EAEA;AACJ;AACA;EACIyD,SAASA,CACL1D,EAA2B,EAC3BC,OAAgB,EACT;IACP,OAAOC,cAAc,CAAC0B,cAAc,CAAC5B,EAAE,EAAEC,OAAO,CAAC;EACrD;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAM0D,YAAY,GAAG,IAAI5B,aAAa,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/provider.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import Animated, { interpolate, interpolateColor, runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated";
|
|
1
2
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
3
|
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
|
|
3
4
|
import { StatusBar } from "react-native";
|
|
4
5
|
import React from "react";
|
|
5
|
-
import Animated, { interpolate, interpolateColor, runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, withSpring, withTiming } from "react-native-reanimated";
|
|
6
6
|
import { eventManager } from "./events";
|
|
7
7
|
export const providerRegistryStack = [];
|
|
8
8
|
|
|
@@ -23,6 +23,11 @@ export function registerSheet(id, Sheet, ...contexts) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Animation configuration for iOS modal sheet style animations.
|
|
28
|
+
* @deprecated Use duration prop directly instead
|
|
29
|
+
*/
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* The SheetProvider makes available the sheets in a given context. The default context is
|
|
28
33
|
* `global`. However if you want to render a Sheet within another sheet or if you want to render
|
|
@@ -44,7 +49,7 @@ export function registerSheet(id, Sheet, ...contexts) {
|
|
|
44
49
|
export function SheetProvider({
|
|
45
50
|
iosModalSheetTypeOfAnimation = false,
|
|
46
51
|
context = "global",
|
|
47
|
-
duration =
|
|
52
|
+
duration = 150,
|
|
48
53
|
children
|
|
49
54
|
}) {
|
|
50
55
|
const {
|
|
@@ -53,25 +58,24 @@ export function SheetProvider({
|
|
|
53
58
|
const [, forceUpdate] = React.useReducer(x => x + 1, 0);
|
|
54
59
|
const sheetIds = Object.keys(sheetsRegistry[context] || sheetsRegistry["global"] || {});
|
|
55
60
|
|
|
56
|
-
// Rerender when a new sheet is added.
|
|
57
|
-
const onRegister = React.useCallback(forceUpdate, [forceUpdate]);
|
|
58
|
-
|
|
59
61
|
// IOS modal sheet type of animation
|
|
60
62
|
const isFullScreen = useSharedValue(-1);
|
|
61
63
|
const colorStyle = useAnimatedStyle(() => ({
|
|
62
64
|
flex: 1,
|
|
63
|
-
backgroundColor: interpolateColor(isFullScreen.value, [0, 1], ["transparent", "#000"])
|
|
65
|
+
backgroundColor: withSpring(interpolateColor(isFullScreen.value, [0, 1], ["transparent", "#000"]), {
|
|
66
|
+
duration
|
|
67
|
+
})
|
|
64
68
|
}));
|
|
65
69
|
const animatedStyle = useAnimatedStyle(() => ({
|
|
66
70
|
flex: 1,
|
|
67
71
|
overflow: "hidden",
|
|
68
72
|
borderRadius: interpolate(isFullScreen.value, [0, 0.8, 1], [0, 20, 24], "clamp"),
|
|
69
73
|
transform: [{
|
|
70
|
-
scaleX:
|
|
74
|
+
scaleX: withSpring(interpolate(isFullScreen.value, [0, 0.8], [1, 0.92], "clamp"), {
|
|
71
75
|
duration
|
|
72
76
|
})
|
|
73
77
|
}, {
|
|
74
|
-
translateY: withSpring(interpolate(isFullScreen.value, [0, 0.
|
|
78
|
+
translateY: withSpring(interpolate(isFullScreen.value, [0, 0.8, 1], [0, top, top + 5], "clamp"), {
|
|
75
79
|
duration,
|
|
76
80
|
dampingRatio: 1.5
|
|
77
81
|
})
|
|
@@ -89,16 +93,17 @@ export function SheetProvider({
|
|
|
89
93
|
}, []);
|
|
90
94
|
React.useEffect(() => {
|
|
91
95
|
providerRegistryStack.indexOf(context) > -1 ? providerRegistryStack.indexOf(context) : providerRegistryStack.push(context) - 1;
|
|
92
|
-
const unsub = eventManager.subscribe(`${context}-on-register`,
|
|
96
|
+
const unsub = eventManager.subscribe(`${context}-on-register`, forceUpdate);
|
|
93
97
|
return () => {
|
|
94
98
|
providerRegistryStack.splice(providerRegistryStack.indexOf(context), 1);
|
|
95
99
|
unsub?.unsubscribe();
|
|
96
100
|
};
|
|
97
|
-
}, [context,
|
|
101
|
+
}, [context, forceUpdate]);
|
|
98
102
|
return /*#__PURE__*/React.createElement(SheetAnimationContext.Provider, {
|
|
99
103
|
value: {
|
|
100
104
|
isFullScreen,
|
|
101
|
-
iosModalSheetTypeOfAnimation
|
|
105
|
+
iosModalSheetTypeOfAnimation,
|
|
106
|
+
duration
|
|
102
107
|
}
|
|
103
108
|
}, /*#__PURE__*/React.createElement(Animated.View, {
|
|
104
109
|
style: colorStyle
|
|
@@ -107,8 +112,7 @@ export function SheetProvider({
|
|
|
107
112
|
}, children)), /*#__PURE__*/React.createElement(BottomSheetModalProvider, null, sheetIds.map(id => /*#__PURE__*/React.createElement(RenderSheet, {
|
|
108
113
|
key: id,
|
|
109
114
|
id: id,
|
|
110
|
-
context: context
|
|
111
|
-
duration: duration
|
|
115
|
+
context: context
|
|
112
116
|
}))));
|
|
113
117
|
}
|
|
114
118
|
const ProviderContext = /*#__PURE__*/React.createContext("global");
|
|
@@ -117,11 +121,20 @@ const SheetAnimationContext = /*#__PURE__*/React.createContext({
|
|
|
117
121
|
isFullScreen: {
|
|
118
122
|
value: 0
|
|
119
123
|
},
|
|
120
|
-
iosModalSheetTypeOfAnimation: false
|
|
124
|
+
iosModalSheetTypeOfAnimation: false,
|
|
125
|
+
duration: 300
|
|
121
126
|
});
|
|
122
127
|
export const SheetRefContext = /*#__PURE__*/React.createContext({});
|
|
123
128
|
const SheetPayloadContext = /*#__PURE__*/React.createContext(undefined);
|
|
124
129
|
|
|
130
|
+
// Stack behavior context for managing sheet transitions
|
|
131
|
+
|
|
132
|
+
const StackBehaviorContext = /*#__PURE__*/React.createContext({
|
|
133
|
+
behavior: "switch",
|
|
134
|
+
isTransitioning: false,
|
|
135
|
+
previousSheetId: null
|
|
136
|
+
});
|
|
137
|
+
|
|
125
138
|
/**
|
|
126
139
|
* Get id of the current context.
|
|
127
140
|
*/
|
|
@@ -134,6 +147,10 @@ export const useSheetIDContext = () => React.useContext(SheetIDContext);
|
|
|
134
147
|
* Get the current sheet animation context.
|
|
135
148
|
*/
|
|
136
149
|
export const useSheetAnimationContext = () => React.useContext(SheetAnimationContext);
|
|
150
|
+
/**
|
|
151
|
+
* Get stack behavior context for the current sheet.
|
|
152
|
+
*/
|
|
153
|
+
export const useStackBehaviorContext = () => React.useContext(StackBehaviorContext);
|
|
137
154
|
/**
|
|
138
155
|
* Get the current Sheet's internal ref.
|
|
139
156
|
*/
|
|
@@ -153,29 +170,44 @@ export function useOnSheet(id, type, listener) {
|
|
|
153
170
|
React.useEffect(() => {
|
|
154
171
|
const subscription = eventManager.subscribe(`${type}_${id}`, listener);
|
|
155
172
|
return () => subscription.unsubscribe();
|
|
156
|
-
}, [id, listener]);
|
|
173
|
+
}, [id, listener, type]);
|
|
157
174
|
}
|
|
158
175
|
const RenderSheet = ({
|
|
159
176
|
id,
|
|
160
|
-
context
|
|
161
|
-
duration
|
|
177
|
+
context
|
|
162
178
|
}) => {
|
|
163
179
|
const [payload, setPayload] = React.useState();
|
|
164
180
|
const [visible, setVisible] = React.useState(false);
|
|
181
|
+
const [stackBehavior, setStackBehavior] = React.useState("switch");
|
|
182
|
+
const [isPending, startTransition] = React.useTransition();
|
|
183
|
+
const [previousSheetId, setPreviousSheetId] = React.useState(null);
|
|
165
184
|
const ref = React.useRef(null);
|
|
166
185
|
const Sheet = context.startsWith("$$-auto-") ? sheetsRegistry?.global?.[id] : sheetsRegistry[context] ? sheetsRegistry[context]?.[id] : undefined;
|
|
167
|
-
const onShow = React.useCallback((data, ctx = "global", reopened) => {
|
|
186
|
+
const onShow = React.useCallback((data, ctx = "global", reopened, behavior) => {
|
|
168
187
|
if (ctx !== context) return;
|
|
169
|
-
if (
|
|
170
|
-
|
|
188
|
+
if (behavior) {
|
|
189
|
+
setStackBehavior(behavior);
|
|
190
|
+
}
|
|
191
|
+
if (!reopened) {
|
|
192
|
+
setPayload(data);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Smooth transition handling using React's useTransition
|
|
196
|
+
startTransition(() => {
|
|
197
|
+
setVisible(true);
|
|
198
|
+
});
|
|
171
199
|
}, [context]);
|
|
172
|
-
const onClose = React.useCallback((_data, ctx = "global", reopened) => {
|
|
200
|
+
const onClose = React.useCallback((_data, ctx = "global", reopened, nextSheetId) => {
|
|
173
201
|
if (context !== ctx) return;
|
|
202
|
+
if (nextSheetId) {
|
|
203
|
+
setPreviousSheetId(nextSheetId);
|
|
204
|
+
}
|
|
174
205
|
if (!reopened) {
|
|
175
206
|
setPayload(undefined);
|
|
176
|
-
|
|
207
|
+
setVisible(false);
|
|
177
208
|
} else {
|
|
178
209
|
setVisible(false);
|
|
210
|
+
setPreviousSheetId(null);
|
|
179
211
|
}
|
|
180
212
|
}, [context]);
|
|
181
213
|
const onHide = React.useCallback((data, ctx = "global") => {
|
|
@@ -187,13 +219,19 @@ const RenderSheet = ({
|
|
|
187
219
|
}
|
|
188
220
|
}, [context, id, payload, visible]);
|
|
189
221
|
React.useEffect(() => {
|
|
190
|
-
|
|
222
|
+
const subs = [eventManager.subscribe(`show_wrap_${id}`, onShow), eventManager.subscribe(`onclose_${id}`, onClose), eventManager.subscribe(`hide_wrap_${id}`, onHide)];
|
|
191
223
|
return () => {
|
|
192
224
|
subs.forEach(s => s.unsubscribe());
|
|
193
225
|
};
|
|
194
226
|
}, [id, context, onShow, onHide, onClose]);
|
|
195
227
|
if (!Sheet) return null;
|
|
196
|
-
|
|
228
|
+
const stackContextValue = {
|
|
229
|
+
behavior: stackBehavior,
|
|
230
|
+
isTransitioning: isPending,
|
|
231
|
+
previousSheetId
|
|
232
|
+
};
|
|
233
|
+
if (!visible) return null;
|
|
234
|
+
return /*#__PURE__*/React.createElement(ProviderContext.Provider, {
|
|
197
235
|
value: context
|
|
198
236
|
}, /*#__PURE__*/React.createElement(SheetIDContext.Provider, {
|
|
199
237
|
value: id
|
|
@@ -201,10 +239,12 @@ const RenderSheet = ({
|
|
|
201
239
|
value: ref
|
|
202
240
|
}, /*#__PURE__*/React.createElement(SheetPayloadContext.Provider, {
|
|
203
241
|
value: payload
|
|
242
|
+
}, /*#__PURE__*/React.createElement(StackBehaviorContext.Provider, {
|
|
243
|
+
value: stackContextValue
|
|
204
244
|
}, /*#__PURE__*/React.createElement(Sheet, {
|
|
205
245
|
id: id,
|
|
206
246
|
payload: payload,
|
|
207
247
|
context: context
|
|
208
|
-
})))))
|
|
248
|
+
}))))));
|
|
209
249
|
};
|
|
210
250
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Animated","interpolate","interpolateColor","runOnJS","useAnimatedReaction","useAnimatedStyle","useSharedValue","withSpring","useSafeAreaInsets","BottomSheetModalProvider","StatusBar","React","eventManager","providerRegistryStack","sheetsRegistry","global","registerSheet","id","Sheet","contexts","length","context","registry","publish","SheetProvider","iosModalSheetTypeOfAnimation","duration","children","top","forceUpdate","useReducer","x","sheetIds","Object","keys","isFullScreen","colorStyle","flex","backgroundColor","value","animatedStyle","overflow","borderRadius","transform","scaleX","translateY","dampingRatio","setStatusBar","setBarStyle","currentValue","useEffect","indexOf","push","unsub","subscribe","splice","unsubscribe","createElement","SheetAnimationContext","Provider","View","style","map","RenderSheet","key","ProviderContext","createContext","SheetIDContext","undefined","SheetRefContext","SheetPayloadContext","StackBehaviorContext","behavior","isTransitioning","previousSheetId","useProviderContext","useContext","useSheetIDContext","useSheetAnimationContext","useStackBehaviorContext","useSheetRef","useSheetPayload","useOnSheet","type","listener","subscription","payload","setPayload","useState","visible","setVisible","stackBehavior","setStackBehavior","isPending","startTransition","useTransition","setPreviousSheetId","ref","useRef","startsWith","onShow","useCallback","data","ctx","reopened","onClose","_data","nextSheetId","onHide","subs","forEach","s","stackContextValue"],"sourceRoot":"../../src","sources":["provider.tsx"],"mappings":"AAAA,OAAOA,QAAQ,IACbC,WAAW,EACXC,gBAAgB,EAChBC,OAAO,EAEPC,mBAAmB,EACnBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAChC,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,wBAAwB,QAAQ,sBAAsB;AAC/D,SAASC,SAAS,QAAQ,cAAc;AACxC,OAAOC,KAAK,MAAM,OAAO;AAGzB,SAASC,YAAY,QAAQ,UAAU;AAEvC,OAAO,MAAMC,qBAA+B,GAAG,EAAE;;AAEjD;AACA;AACA;AACA,OAAO,MAAMC,cAEZ,GAAG;EACFC,MAAM,EAAE,CAAC;AACX,CAAC;AAOD;AACA,OAAO,SAASC,aAAaA,CAC3BC,EAA2B,EAC3BC,KAAwB,EACxB,GAAGC,QAAkB,EACrB;EACA,IAAI,CAACF,EAAE,IAAI,CAACC,KAAK,EAAE;EACnB,IAAI,CAACC,QAAQ,IAAIA,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAED,QAAQ,GAAG,CAAC,QAAQ,CAAC;EAC7D,KAAK,IAAIE,OAAO,IAAIF,QAAQ,EAAE;IAC5B,MAAMG,QAAQ,GAAG,CAACR,cAAc,CAACO,OAAO,CAAC,GACpCP,cAAc,CAACO,OAAO,CAAC,GAAG,CAAC,CAAC,GAC7BP,cAAc,CAACO,OAAO,CAAC;IAC3BC,QAAQ,CAACL,EAAE,CAAW,GAAGC,KAAK;IAC9BN,YAAY,CAACW,OAAO,CAAC,GAAGF,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,EAAEQ,MAAM,EAAEH,OAAO,CAAC,CAAC;EAE1C,IAAI,CAACvF,KAAK,EAAE,OAAO,IAAI;EAEvB,MAAM8F,iBAA4C,GAAG;IACnDxC,QAAQ,EAAEmB,aAAa;IACvBlB,eAAe,EAAEoB,SAAS;IAC1BnB;EACF,CAAC;EAED,IAAI,CAACe,OAAO,EAAE,OAAO,IAAI;EAEzB,oBACE9E,KAAA,CAAA8C,aAAA,CAACQ,eAAe,CAACN,QAAQ;IAACpB,KAAK,EAAElB;EAAQ,gBACvCV,KAAA,CAAA8C,aAAA,CAACU,cAAc,CAACR,QAAQ;IAACpB,KAAK,EAAEtB;EAAG,gBACjCN,KAAA,CAAA8C,aAAA,CAACY,eAAe,CAACV,QAAQ;IAACpB,KAAK,EAAE0D;EAAI,gBACnCtF,KAAA,CAAA8C,aAAA,CAACa,mBAAmB,CAACX,QAAQ;IAACpB,KAAK,EAAE+C;EAAQ,gBAC3C3E,KAAA,CAAA8C,aAAA,CAACc,oBAAoB,CAACZ,QAAQ;IAACpB,KAAK,EAAEyE;EAAkB,gBACtDrG,KAAA,CAAA8C,aAAA,CAACvC,KAAK;IAACD,EAAE,EAAEA,EAAG;IAACqE,OAAO,EAAEA,OAAQ;IAACjE,OAAO,EAAEA;EAAQ,CAAE,CACvB,CACH,CACN,CACH,CACD,CAAC;AAE/B,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import { createNavigatorFactory, useNavigationBuilder } from "@react-navigation/native";
|
|
3
|
-
import React from "react";
|
|
3
|
+
import * as React from "react";
|
|
4
4
|
import { BottomSheetRouter } from "./router";
|
|
5
5
|
import { BottomSheetView } from "./view";
|
|
6
6
|
function BottomSheetNavigator({
|
|
@@ -8,6 +8,7 @@ function BottomSheetNavigator({
|
|
|
8
8
|
children,
|
|
9
9
|
screenListeners,
|
|
10
10
|
screenOptions,
|
|
11
|
+
initialRouteName,
|
|
11
12
|
...rest
|
|
12
13
|
}) {
|
|
13
14
|
const {
|
|
@@ -19,7 +20,8 @@ function BottomSheetNavigator({
|
|
|
19
20
|
id,
|
|
20
21
|
children,
|
|
21
22
|
screenListeners,
|
|
22
|
-
screenOptions
|
|
23
|
+
screenOptions,
|
|
24
|
+
initialRouteName
|
|
23
25
|
});
|
|
24
26
|
return /*#__PURE__*/React.createElement(NavigationContent, null, /*#__PURE__*/React.createElement(BottomSheetView, _extends({}, rest, {
|
|
25
27
|
state: state,
|
|
@@ -29,18 +31,40 @@ function BottomSheetNavigator({
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* Creates a bottom sheet navigator that renders screens as bottom sheet modals.
|
|
35
|
+
*
|
|
36
|
+
* The first screen in the navigator is rendered as the main content,
|
|
37
|
+
* and subsequent screens are rendered as bottom sheet modals on top.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* // With React Navigation
|
|
42
|
+
* const { Navigator, Screen } = createBottomSheetNavigator();
|
|
43
|
+
*
|
|
44
|
+
* function App() {
|
|
45
|
+
* return (
|
|
46
|
+
* <Navigator>
|
|
47
|
+
* <Screen name="Home" component={HomeScreen} />
|
|
48
|
+
* <Screen
|
|
49
|
+
* name="Details"
|
|
50
|
+
* component={DetailsSheet}
|
|
51
|
+
* options={{ snapPoints: ['50%', '100%'] }}
|
|
52
|
+
* />
|
|
53
|
+
* </Navigator>
|
|
54
|
+
* );
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
34
57
|
*
|
|
35
58
|
* @example
|
|
36
59
|
* ```tsx
|
|
60
|
+
* // With Expo Router
|
|
61
|
+
* import { Slot, withLayoutContext } from "expo-router";
|
|
37
62
|
* import {
|
|
38
63
|
* createBottomSheetNavigator,
|
|
39
64
|
* BottomSheetNavigationOptions,
|
|
40
65
|
* BottomSheetNavigationEventMap,
|
|
41
66
|
* BottomSheetNavigationState,
|
|
42
|
-
* } from "@
|
|
43
|
-
* import { Slot, withLayoutContext } from "expo-router";
|
|
67
|
+
* } from "@niibase/bottom-sheet-manager";
|
|
44
68
|
*
|
|
45
69
|
* const { Navigator } = createBottomSheetNavigator();
|
|
46
70
|
*
|
|
@@ -56,24 +80,16 @@ function BottomSheetNavigator({
|
|
|
56
80
|
* };
|
|
57
81
|
*
|
|
58
82
|
* export default function Layout() {
|
|
83
|
+
* // SSR guard - navigator doesn't work on server
|
|
59
84
|
* if (typeof window === "undefined") return <Slot />;
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* screenOptions={
|
|
63
|
-
* {
|
|
64
|
-
* // API Reference: `@repo/design/bottom-sheet/types.ts`
|
|
65
|
-
* // And: https://gorhom.github.io/react-native-bottom-sheet/modal/props/
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
*. />
|
|
69
|
-
* );
|
|
85
|
+
*
|
|
86
|
+
* return <BottomSheet />;
|
|
70
87
|
* }
|
|
71
88
|
* ```
|
|
72
89
|
*/
|
|
73
90
|
export function createBottomSheetNavigator(config) {
|
|
74
|
-
// We call `createNavigatorFactory` with our un-typed navigator
|
|
75
|
-
// but pass in the config to get the typed container
|
|
76
91
|
return createNavigatorFactory(BottomSheetNavigator)(config);
|
|
77
92
|
}
|
|
78
93
|
export * from "./types";
|
|
94
|
+
export { BottomSheetActions, useBottomSheetNavigation } from "./router";
|
|
79
95
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createNavigatorFactory","useNavigationBuilder","React","BottomSheetRouter","BottomSheetView","BottomSheetNavigator","id","children","screenListeners","screenOptions","rest","state","descriptors","navigation","NavigationContent","createElement","_extends","createBottomSheetNavigator","config"],"sourceRoot":"../../../src","sources":["router/index.tsx"],"mappings":";AAAA,SACEA,sBAAsB,
|
|
1
|
+
{"version":3,"names":["createNavigatorFactory","useNavigationBuilder","React","BottomSheetRouter","BottomSheetView","BottomSheetNavigator","id","children","screenListeners","screenOptions","initialRouteName","rest","state","descriptors","navigation","NavigationContent","createElement","_extends","createBottomSheetNavigator","config","BottomSheetActions","useBottomSheetNavigation"],"sourceRoot":"../../../src","sources":["router/index.tsx"],"mappings":";AAAA,SACEA,sBAAsB,EACtBC,oBAAoB,QAKf,0BAA0B;AACjC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAU9B,SAASC,iBAAiB,QAAuC,UAAU;AAC3E,SAASC,eAAe,QAAQ,QAAQ;AAExC,SAASC,oBAAoBA,CAAC;EAC5BC,EAAE;EACFC,QAAQ;EACRC,eAAe;EACfC,aAAa;EACbC,gBAAgB;EAChB,GAAGC;AACsB,CAAC,EAAE;EAC5B,MAAM;IAAEC,KAAK;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAkB,CAAC,GAAGd,oBAAoB,CAMhFE,iBAAiB,EAAE;IACnBG,EAAE;IACFC,QAAQ;IACRC,eAAe;IACfC,aAAa;IACbC;EACF,CAAC,CAAC;EAEF,oBACER,KAAA,CAAAc,aAAA,CAACD,iBAAiB,qBAChBb,KAAA,CAAAc,aAAA,CAACZ,eAAe,EAAAa,QAAA,KACVN,IAAI;IACRC,KAAK,EAAEA,KAAM;IACbE,UAAU,EAAEA,UAAW;IACvBD,WAAW,EAAEA;EAAY,EAC1B,CACgB,CAAC;AAExB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,0BAA0BA,CAmBxCC,MAAe,EAAmC;EAClD,OAAOnB,sBAAsB,CAACK,oBAAoB,CAAC,CAACc,MAAM,CAAC;AAC7D;AAEA,cAAc,SAAS;AACvB,SAASC,kBAAkB,EAAEC,wBAAwB,QAAQ,UAAU","ignoreList":[]}
|