@mustmove/overlay-kit-rn 1.0.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/dist/index.mjs ADDED
@@ -0,0 +1,821 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/context/provider/index.tsx
34
+ import {
35
+ useCallback as useCallback2,
36
+ useEffect as useEffect5,
37
+ useReducer
38
+ } from "react";
39
+
40
+ // src/context/provider/content-overlay-controller.tsx
41
+ import { memo, useEffect } from "react";
42
+ import { jsx } from "react/jsx-runtime";
43
+ var ContentOverlayController = memo(
44
+ ({
45
+ isOpen,
46
+ overlayId,
47
+ overlayDispatch,
48
+ controller: Controller
49
+ }) => {
50
+ useEffect(() => {
51
+ setImmediate(() => {
52
+ overlayDispatch({ type: "OPEN", overlayId });
53
+ });
54
+ }, [overlayDispatch, overlayId]);
55
+ return /* @__PURE__ */ jsx(
56
+ Controller,
57
+ {
58
+ isOpen,
59
+ overlayId,
60
+ close: () => overlayDispatch({ type: "CLOSE", overlayId }),
61
+ unmount: () => overlayDispatch({ type: "REMOVE", overlayId })
62
+ }
63
+ );
64
+ }
65
+ );
66
+
67
+ // src/context/provider/bottom-sheet-controller.tsx
68
+ import {
69
+ memo as memo2,
70
+ useEffect as useEffect2,
71
+ useRef,
72
+ useCallback
73
+ } from "react";
74
+ import BottomSheet, {
75
+ BottomSheetBackdrop
76
+ } from "@gorhom/bottom-sheet";
77
+ import {
78
+ StyleSheet
79
+ } from "react-native";
80
+ import { useReducedMotion } from "react-native-reanimated";
81
+ import { jsx as jsx2 } from "react/jsx-runtime";
82
+ var ContentBottomSheetController = memo2(
83
+ ({
84
+ isOpen,
85
+ overlayId,
86
+ overlayDispatch,
87
+ controller: Controller,
88
+ options = {}
89
+ }) => {
90
+ console.log("\u{1F680} ~ Controller:", Controller);
91
+ const bottomSheetRef = useRef(null);
92
+ const reducedMotion = useReducedMotion();
93
+ const _a = options, {
94
+ snapPoints = ["50%", "90%"],
95
+ enablePanDownToClose = true,
96
+ enableBackdrop = true,
97
+ backdropOpacity = 0.5,
98
+ enableDynamicSizing = true,
99
+ backgroundStyle = {},
100
+ handleStyle = {}
101
+ } = _a, restOptions = __objRest(_a, [
102
+ "snapPoints",
103
+ "enablePanDownToClose",
104
+ "enableBackdrop",
105
+ "backdropOpacity",
106
+ "enableDynamicSizing",
107
+ "backgroundStyle",
108
+ "handleStyle"
109
+ ]);
110
+ useEffect2(() => {
111
+ var _a2;
112
+ if (isOpen) {
113
+ const rafId = requestAnimationFrame(() => {
114
+ var _a3;
115
+ (_a3 = bottomSheetRef.current) == null ? void 0 : _a3.expand();
116
+ overlayDispatch({ type: "OPEN", overlayId });
117
+ });
118
+ return () => cancelAnimationFrame(rafId);
119
+ } else {
120
+ (_a2 = bottomSheetRef.current) == null ? void 0 : _a2.close();
121
+ }
122
+ }, [isOpen, overlayDispatch, overlayId]);
123
+ const handleClose = useCallback(() => {
124
+ overlayDispatch({ type: "CLOSE", overlayId });
125
+ }, [overlayDispatch, overlayId]);
126
+ const renderBackdrop = useCallback(
127
+ (props) => /* @__PURE__ */ jsx2(
128
+ BottomSheetBackdrop,
129
+ __spreadProps(__spreadValues({}, props), {
130
+ appearsOnIndex: 0,
131
+ disappearsOnIndex: -1,
132
+ opacity: backdropOpacity,
133
+ pressBehavior: "close"
134
+ })
135
+ ),
136
+ [backdropOpacity]
137
+ );
138
+ if (!isOpen) return null;
139
+ return /* @__PURE__ */ jsx2(
140
+ BottomSheet,
141
+ {
142
+ ref: bottomSheetRef,
143
+ android_keyboardInputMode: "adjustResize",
144
+ keyboardBehavior: "extend",
145
+ snapPoints: enableDynamicSizing ? void 0 : snapPoints,
146
+ enablePanDownToClose,
147
+ onClose: handleClose,
148
+ index: 0,
149
+ backdropComponent: enableBackdrop ? renderBackdrop : void 0,
150
+ backgroundStyle: [
151
+ {
152
+ borderTopLeftRadius: 16,
153
+ borderTopRightRadius: 16
154
+ },
155
+ backgroundStyle
156
+ ],
157
+ handleStyle: [
158
+ {
159
+ backgroundColor: "transparent",
160
+ borderTopLeftRadius: 16,
161
+ borderTopRightRadius: 16
162
+ },
163
+ handleStyle
164
+ ],
165
+ enableDynamicSizing,
166
+ animateOnMount: !reducedMotion,
167
+ children: /* @__PURE__ */ jsx2(
168
+ Controller,
169
+ __spreadValues({
170
+ isOpen,
171
+ overlayId,
172
+ snapPoints,
173
+ enablePanDownToClose,
174
+ close: () => overlayDispatch({ type: "CLOSE", overlayId }),
175
+ unmount: () => overlayDispatch({ type: "REMOVE", overlayId })
176
+ }, restOptions)
177
+ )
178
+ }
179
+ );
180
+ }
181
+ );
182
+ var styles = StyleSheet.create({
183
+ contentContainer: {
184
+ flex: 1
185
+ }
186
+ });
187
+
188
+ // src/context/provider/modal-controller.tsx
189
+ import { memo as memo3, useEffect as useEffect3, useState } from "react";
190
+ import {
191
+ Modal,
192
+ TouchableWithoutFeedback,
193
+ Animated,
194
+ StyleSheet as StyleSheet2,
195
+ Dimensions
196
+ } from "react-native";
197
+ import { jsx as jsx3 } from "react/jsx-runtime";
198
+ var { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("window");
199
+ var ContentModalController = memo3(
200
+ ({
201
+ isOpen,
202
+ overlayId,
203
+ overlayDispatch,
204
+ controller: Controller,
205
+ options = {}
206
+ }) => {
207
+ const {
208
+ modalType = "center",
209
+ backdropOpacity = 0.5,
210
+ animationType = "fade",
211
+ swipeDirection
212
+ } = options;
213
+ const [backdropAnimation] = useState(new Animated.Value(0));
214
+ const [contentAnimation] = useState(new Animated.Value(0));
215
+ useEffect3(() => {
216
+ if (isOpen) {
217
+ setImmediate(() => {
218
+ overlayDispatch({ type: "OPEN", overlayId });
219
+ });
220
+ Animated.parallel([
221
+ Animated.timing(backdropAnimation, {
222
+ toValue: 1,
223
+ duration: 300,
224
+ useNativeDriver: true
225
+ }),
226
+ Animated.timing(contentAnimation, {
227
+ toValue: 1,
228
+ duration: 300,
229
+ useNativeDriver: true
230
+ })
231
+ ]).start();
232
+ } else {
233
+ Animated.parallel([
234
+ Animated.timing(backdropAnimation, {
235
+ toValue: 0,
236
+ duration: 200,
237
+ useNativeDriver: true
238
+ }),
239
+ Animated.timing(contentAnimation, {
240
+ toValue: 0,
241
+ duration: 200,
242
+ useNativeDriver: true
243
+ })
244
+ ]).start();
245
+ }
246
+ }, [
247
+ isOpen,
248
+ overlayDispatch,
249
+ overlayId,
250
+ backdropAnimation,
251
+ contentAnimation
252
+ ]);
253
+ const handleClose = () => {
254
+ overlayDispatch({ type: "CLOSE", overlayId });
255
+ };
256
+ const getContainerStyle = () => {
257
+ switch (modalType) {
258
+ case "bottom":
259
+ return styles2.bottomContainer;
260
+ case "top":
261
+ return styles2.topContainer;
262
+ case "left":
263
+ return styles2.leftContainer;
264
+ case "right":
265
+ return styles2.rightContainer;
266
+ default:
267
+ return styles2.centerContainer;
268
+ }
269
+ };
270
+ const getContentAnimationStyle = () => {
271
+ const baseOpacity = {
272
+ opacity: contentAnimation
273
+ };
274
+ switch (modalType) {
275
+ case "bottom":
276
+ return __spreadProps(__spreadValues({}, baseOpacity), {
277
+ transform: [
278
+ {
279
+ translateY: contentAnimation.interpolate({
280
+ inputRange: [0, 1],
281
+ outputRange: [SCREEN_HEIGHT, 0]
282
+ })
283
+ }
284
+ ]
285
+ });
286
+ case "top":
287
+ return __spreadProps(__spreadValues({}, baseOpacity), {
288
+ transform: [
289
+ {
290
+ translateY: contentAnimation.interpolate({
291
+ inputRange: [0, 1],
292
+ outputRange: [-SCREEN_HEIGHT, 0]
293
+ })
294
+ }
295
+ ]
296
+ });
297
+ case "left":
298
+ return __spreadProps(__spreadValues({}, baseOpacity), {
299
+ transform: [
300
+ {
301
+ translateX: contentAnimation.interpolate({
302
+ inputRange: [0, 1],
303
+ outputRange: [-SCREEN_WIDTH, 0]
304
+ })
305
+ }
306
+ ]
307
+ });
308
+ case "right":
309
+ return __spreadProps(__spreadValues({}, baseOpacity), {
310
+ transform: [
311
+ {
312
+ translateX: contentAnimation.interpolate({
313
+ inputRange: [0, 1],
314
+ outputRange: [SCREEN_WIDTH, 0]
315
+ })
316
+ }
317
+ ]
318
+ });
319
+ default:
320
+ if (animationType === "slide") {
321
+ return __spreadProps(__spreadValues({}, baseOpacity), {
322
+ transform: [
323
+ {
324
+ scale: contentAnimation.interpolate({
325
+ inputRange: [0, 1],
326
+ outputRange: [0.8, 1]
327
+ })
328
+ }
329
+ ]
330
+ });
331
+ }
332
+ return baseOpacity;
333
+ }
334
+ };
335
+ if (!isOpen) return null;
336
+ return /* @__PURE__ */ jsx3(
337
+ Modal,
338
+ {
339
+ visible: isOpen,
340
+ transparent: true,
341
+ animationType: "none",
342
+ onRequestClose: handleClose,
343
+ statusBarTranslucent: true,
344
+ presentationStyle: "overFullScreen",
345
+ children: /* @__PURE__ */ jsx3(TouchableWithoutFeedback, { onPress: handleClose, children: /* @__PURE__ */ jsx3(
346
+ Animated.View,
347
+ {
348
+ style: [
349
+ styles2.backdrop,
350
+ {
351
+ backgroundColor: `rgba(0, 0, 0, ${backdropOpacity})`,
352
+ opacity: backdropAnimation
353
+ }
354
+ ],
355
+ children: /* @__PURE__ */ jsx3(TouchableWithoutFeedback, { children: /* @__PURE__ */ jsx3(
356
+ Animated.View,
357
+ {
358
+ style: [getContainerStyle(), getContentAnimationStyle()],
359
+ children: /* @__PURE__ */ jsx3(
360
+ Controller,
361
+ {
362
+ isOpen,
363
+ overlayId,
364
+ modalType,
365
+ backdropOpacity,
366
+ animationType,
367
+ swipeDirection,
368
+ close: () => overlayDispatch({ type: "CLOSE", overlayId }),
369
+ unmount: () => overlayDispatch({ type: "REMOVE", overlayId })
370
+ }
371
+ )
372
+ }
373
+ ) })
374
+ }
375
+ ) })
376
+ }
377
+ );
378
+ }
379
+ );
380
+ var styles2 = StyleSheet2.create({
381
+ backdrop: {
382
+ flex: 1,
383
+ backgroundColor: "rgba(0, 0, 0, 0.5)"
384
+ },
385
+ centerContainer: {
386
+ flex: 1,
387
+ justifyContent: "center",
388
+ alignItems: "center",
389
+ paddingHorizontal: 20
390
+ },
391
+ bottomContainer: {
392
+ flex: 1,
393
+ justifyContent: "flex-end"
394
+ },
395
+ topContainer: {
396
+ flex: 1,
397
+ justifyContent: "flex-start"
398
+ },
399
+ leftContainer: {
400
+ flex: 1,
401
+ justifyContent: "center",
402
+ alignItems: "flex-start"
403
+ },
404
+ rightContainer: {
405
+ flex: 1,
406
+ justifyContent: "center",
407
+ alignItems: "flex-end"
408
+ }
409
+ });
410
+
411
+ // src/utils/create-use-external-events.ts
412
+ import { useEffect as useEffect4 } from "react";
413
+
414
+ // src/utils/emitter.ts
415
+ function createEmitter(all) {
416
+ all = all || /* @__PURE__ */ new Map();
417
+ return {
418
+ all,
419
+ on(type, handler) {
420
+ const handlers = all.get(type);
421
+ if (handlers) {
422
+ handlers.push(handler);
423
+ } else {
424
+ all.set(type, [handler]);
425
+ }
426
+ },
427
+ off(type, handler) {
428
+ const handlers = all.get(type);
429
+ if (handlers) {
430
+ if (handler) {
431
+ handlers.splice(handlers.indexOf(handler) >>> 0, 1);
432
+ } else {
433
+ all.set(type, []);
434
+ }
435
+ }
436
+ },
437
+ emit(type, evt) {
438
+ let handlers = all.get(type);
439
+ if (handlers) {
440
+ handlers.slice().forEach((handler) => {
441
+ handler(evt);
442
+ });
443
+ }
444
+ handlers = all.get("*");
445
+ if (handlers) {
446
+ handlers.slice().forEach((handler) => {
447
+ handler(type, evt);
448
+ });
449
+ }
450
+ }
451
+ };
452
+ }
453
+
454
+ // src/utils/create-use-external-events.ts
455
+ var emitter = createEmitter();
456
+ function useClientEffect(...args) {
457
+ useEffect4(...args);
458
+ }
459
+ function dispatchEvent(type, detail) {
460
+ emitter.emit(type, detail);
461
+ }
462
+ function createUseExternalEvents(prefix) {
463
+ function useExternalEvents(events) {
464
+ const handlers = Object.keys(events).reduce(
465
+ (prev, eventKey) => {
466
+ const currentEventKeys = `${prefix}:${eventKey}`;
467
+ return __spreadProps(__spreadValues({}, prev), {
468
+ [currentEventKeys]: function(event) {
469
+ events[eventKey](event);
470
+ }
471
+ });
472
+ },
473
+ {}
474
+ );
475
+ useClientEffect(() => {
476
+ Object.keys(handlers).forEach((eventKey) => {
477
+ emitter.off(eventKey, handlers[eventKey]);
478
+ emitter.on(eventKey, handlers[eventKey]);
479
+ });
480
+ return () => Object.keys(handlers).forEach((eventKey) => {
481
+ emitter.off(eventKey, handlers[eventKey]);
482
+ });
483
+ }, [handlers]);
484
+ }
485
+ function createEvent(event) {
486
+ return (...payload) => dispatchEvent(`${prefix}:${String(event)}`, payload[0]);
487
+ }
488
+ return [useExternalEvents, createEvent];
489
+ }
490
+
491
+ // src/utils/random-id.ts
492
+ function randomId() {
493
+ return `overlay-kit-${Math.random().toString(36).slice(2, 11)}`;
494
+ }
495
+
496
+ // src/event.ts
497
+ function createOverlay(overlayId) {
498
+ const [useOverlayEvent, createEvent] = createUseExternalEvents(
499
+ `${overlayId}/overlay-kit`
500
+ );
501
+ const open = (controller, options) => {
502
+ var _a, _b;
503
+ const overlayId2 = (_a = options == null ? void 0 : options.overlayId) != null ? _a : randomId();
504
+ const componentKey = randomId();
505
+ const overlayType = (_b = options == null ? void 0 : options.overlayType) != null ? _b : "overlay";
506
+ const dispatchOpenEvent = createEvent("open");
507
+ const _c = options || {}, { overlayId: _, overlayType: __ } = _c, restOptions = __objRest(_c, ["overlayId", "overlayType"]);
508
+ dispatchOpenEvent({
509
+ controller,
510
+ overlayId: overlayId2,
511
+ componentKey,
512
+ overlayType,
513
+ options: restOptions
514
+ });
515
+ return overlayId2;
516
+ };
517
+ const openAsync = async (controller, options) => {
518
+ return new Promise((resolve) => {
519
+ const wrappedController = (overlayProps, ...deprecatedLegacyContext) => {
520
+ const close2 = (param) => {
521
+ resolve(param);
522
+ overlayProps.close();
523
+ };
524
+ const unmount2 = (param) => {
525
+ resolve(param);
526
+ overlayProps.unmount();
527
+ };
528
+ const props = __spreadProps(__spreadValues({}, overlayProps), { close: close2, unmount: unmount2 });
529
+ return controller(props);
530
+ };
531
+ open(wrappedController, options);
532
+ });
533
+ };
534
+ const close = createEvent("close");
535
+ const unmount = createEvent("unmount");
536
+ const closeAll = createEvent("closeAll");
537
+ const unmountAll = createEvent("unmountAll");
538
+ return {
539
+ open,
540
+ openAsync,
541
+ close,
542
+ unmount,
543
+ closeAll,
544
+ unmountAll,
545
+ useOverlayEvent
546
+ };
547
+ }
548
+
549
+ // src/utils/create-safe-context.ts
550
+ import { createContext, useContext } from "react";
551
+ var NullSymbol = Symbol("Null");
552
+ function createSafeContext(displayName) {
553
+ const Context = createContext(NullSymbol);
554
+ Context.displayName = displayName != null ? displayName : "SafeContext";
555
+ function useSafeContext() {
556
+ const context = useContext(Context);
557
+ if (context === NullSymbol) {
558
+ const error = new Error(`[${Context.displayName}]: Provider not found.`);
559
+ error.name = "[Error] Context";
560
+ throw error;
561
+ }
562
+ return context;
563
+ }
564
+ return [Context.Provider, useSafeContext];
565
+ }
566
+
567
+ // src/context/context.ts
568
+ function createOverlaySafeContext() {
569
+ const [OverlayContextProvider, useOverlayContext] = createSafeContext("overlay-kit/OverlayContext");
570
+ function useCurrentOverlay2() {
571
+ return useOverlayContext().current;
572
+ }
573
+ function useOverlayData2() {
574
+ return useOverlayContext().overlayData;
575
+ }
576
+ return { OverlayContextProvider, useCurrentOverlay: useCurrentOverlay2, useOverlayData: useOverlayData2 };
577
+ }
578
+
579
+ // src/context/reducer.ts
580
+ var determineCurrentOverlayId = (overlayOrderList, overlayData, targetOverlayId) => {
581
+ var _a, _b;
582
+ const openedOverlayOrderList = overlayOrderList.filter(
583
+ (orderedOverlayId) => overlayData[orderedOverlayId].isOpen === true
584
+ );
585
+ const targetIndexInOpenedList = openedOverlayOrderList.findIndex((item) => item === targetOverlayId);
586
+ return targetIndexInOpenedList === openedOverlayOrderList.length - 1 ? (_a = openedOverlayOrderList[targetIndexInOpenedList - 1]) != null ? _a : null : (_b = openedOverlayOrderList[openedOverlayOrderList.length - 1]) != null ? _b : null;
587
+ };
588
+ function overlayReducer(state, action) {
589
+ switch (action.type) {
590
+ case "ADD": {
591
+ if (state.overlayData[action.overlay.id] != null && state.overlayData[action.overlay.id].isOpen === false) {
592
+ const overlay2 = state.overlayData[action.overlay.id];
593
+ if (overlay2 == null || overlay2.isOpen) {
594
+ return state;
595
+ }
596
+ return __spreadProps(__spreadValues({}, state), {
597
+ current: action.overlay.id,
598
+ overlayData: __spreadProps(__spreadValues({}, state.overlayData), {
599
+ [action.overlay.id]: __spreadProps(__spreadValues({}, overlay2), { isOpen: true })
600
+ })
601
+ });
602
+ }
603
+ const isExisted = state.overlayOrderList.includes(action.overlay.id);
604
+ if (isExisted && state.overlayData[action.overlay.id].isOpen === true) {
605
+ throw new Error(
606
+ `You can't open the multiple overlays with the same overlayId(${action.overlay.id}). Please set a different id.`
607
+ );
608
+ }
609
+ return {
610
+ current: action.overlay.id,
611
+ /**
612
+ * @description Brings the overlay to the front when reopened after closing without unmounting.
613
+ */
614
+ overlayOrderList: [...state.overlayOrderList.filter((item) => item !== action.overlay.id), action.overlay.id],
615
+ overlayData: isExisted ? state.overlayData : __spreadProps(__spreadValues({}, state.overlayData), {
616
+ [action.overlay.id]: action.overlay
617
+ })
618
+ };
619
+ }
620
+ case "OPEN": {
621
+ const overlay2 = state.overlayData[action.overlayId];
622
+ if (overlay2 == null || overlay2.isOpen) {
623
+ return state;
624
+ }
625
+ return __spreadProps(__spreadValues({}, state), {
626
+ overlayData: __spreadProps(__spreadValues({}, state.overlayData), {
627
+ [action.overlayId]: __spreadProps(__spreadValues({}, overlay2), { isOpen: true, isMounted: true })
628
+ })
629
+ });
630
+ }
631
+ case "CLOSE": {
632
+ const overlay2 = state.overlayData[action.overlayId];
633
+ if (overlay2 == null || !overlay2.isOpen) {
634
+ return state;
635
+ }
636
+ const currentOverlayId = determineCurrentOverlayId(state.overlayOrderList, state.overlayData, action.overlayId);
637
+ return __spreadProps(__spreadValues({}, state), {
638
+ current: currentOverlayId,
639
+ overlayData: __spreadProps(__spreadValues({}, state.overlayData), {
640
+ [action.overlayId]: __spreadProps(__spreadValues({}, state.overlayData[action.overlayId]), {
641
+ isOpen: false
642
+ })
643
+ })
644
+ });
645
+ }
646
+ case "REMOVE": {
647
+ const overlay2 = state.overlayData[action.overlayId];
648
+ if (overlay2 == null) {
649
+ return state;
650
+ }
651
+ const remainingOverlays = state.overlayOrderList.filter((item) => item !== action.overlayId);
652
+ if (state.overlayOrderList.length === remainingOverlays.length) {
653
+ return state;
654
+ }
655
+ const copiedOverlayData = __spreadValues({}, state.overlayData);
656
+ delete copiedOverlayData[action.overlayId];
657
+ const currentOverlayId = determineCurrentOverlayId(state.overlayOrderList, state.overlayData, action.overlayId);
658
+ return {
659
+ current: currentOverlayId,
660
+ overlayOrderList: remainingOverlays,
661
+ overlayData: copiedOverlayData
662
+ };
663
+ }
664
+ case "CLOSE_ALL": {
665
+ if (Object.keys(state.overlayData).length === 0) {
666
+ return state;
667
+ }
668
+ return __spreadProps(__spreadValues({}, state), {
669
+ current: null,
670
+ overlayData: Object.keys(state.overlayData).reduce(
671
+ (prev, curr) => __spreadProps(__spreadValues({}, prev), {
672
+ [curr]: __spreadProps(__spreadValues({}, state.overlayData[curr]), {
673
+ isOpen: false
674
+ })
675
+ }),
676
+ {}
677
+ )
678
+ });
679
+ }
680
+ case "REMOVE_ALL": {
681
+ return { current: null, overlayOrderList: [], overlayData: {} };
682
+ }
683
+ }
684
+ }
685
+
686
+ // src/context/provider/index.tsx
687
+ import { GestureHandlerRootView } from "react-native-gesture-handler";
688
+ import { BottomSheetModalProvider as BottomSheetModalProvider2 } from "@gorhom/bottom-sheet";
689
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
690
+ function createOverlayProvider() {
691
+ const overlayId = randomId();
692
+ const _a = createOverlay(overlayId), { useOverlayEvent } = _a, overlay2 = __objRest(_a, ["useOverlayEvent"]);
693
+ const { OverlayContextProvider, useCurrentOverlay: useCurrentOverlay2, useOverlayData: useOverlayData2 } = createOverlaySafeContext();
694
+ function OverlayProvider2({ children }) {
695
+ const [overlayState, overlayDispatch] = useReducer(overlayReducer, {
696
+ current: null,
697
+ overlayOrderList: [],
698
+ overlayData: {}
699
+ });
700
+ const overlayOpen = useCallback2(
701
+ ({
702
+ controller,
703
+ overlayId: overlayId2,
704
+ componentKey,
705
+ overlayType = "overlay",
706
+ options
707
+ }) => {
708
+ overlayDispatch({
709
+ type: "ADD",
710
+ overlay: {
711
+ id: overlayId2,
712
+ componentKey,
713
+ isOpen: true,
714
+ isMounted: true,
715
+ controller,
716
+ overlayType,
717
+ options
718
+ }
719
+ });
720
+ },
721
+ []
722
+ );
723
+ const close = useCallback2((overlayId2) => {
724
+ overlayDispatch({ type: "CLOSE", overlayId: overlayId2 });
725
+ }, []);
726
+ const unmount = useCallback2((overlayId2) => {
727
+ overlayDispatch({ type: "REMOVE", overlayId: overlayId2 });
728
+ }, []);
729
+ const closeAll = useCallback2(() => {
730
+ overlayDispatch({ type: "CLOSE_ALL" });
731
+ }, []);
732
+ const unmountAll = useCallback2(() => {
733
+ overlayDispatch({ type: "REMOVE_ALL" });
734
+ }, []);
735
+ useOverlayEvent({
736
+ open: overlayOpen,
737
+ close,
738
+ unmount,
739
+ closeAll,
740
+ unmountAll
741
+ });
742
+ useEffect5(() => {
743
+ return () => {
744
+ overlayDispatch({ type: "REMOVE_ALL" });
745
+ };
746
+ }, []);
747
+ return /* @__PURE__ */ jsx4(GestureHandlerRootView, { style: { flex: 1 }, children: /* @__PURE__ */ jsx4(BottomSheetModalProvider2, { children: /* @__PURE__ */ jsxs(OverlayContextProvider, { value: overlayState, children: [
748
+ children,
749
+ overlayState.overlayOrderList.map((item) => {
750
+ const overlayItem = overlayState.overlayData[item];
751
+ const {
752
+ id: currentOverlayId,
753
+ componentKey,
754
+ isOpen,
755
+ controller: Controller,
756
+ overlayType,
757
+ options
758
+ } = overlayItem;
759
+ if (overlayType === "bottomSheet") {
760
+ return /* @__PURE__ */ jsx4(
761
+ ContentBottomSheetController,
762
+ {
763
+ isOpen,
764
+ controller: Controller,
765
+ overlayId: currentOverlayId,
766
+ overlayDispatch,
767
+ options
768
+ },
769
+ componentKey
770
+ );
771
+ } else if (overlayType === "modal") {
772
+ const isCurrentModal = overlayState.current === currentOverlayId;
773
+ const shouldShow = isOpen && isCurrentModal;
774
+ return /* @__PURE__ */ jsx4(
775
+ ContentModalController,
776
+ {
777
+ isOpen: shouldShow,
778
+ controller: Controller,
779
+ overlayId: currentOverlayId,
780
+ overlayDispatch,
781
+ options
782
+ },
783
+ componentKey
784
+ );
785
+ } else {
786
+ return /* @__PURE__ */ jsx4(
787
+ ContentOverlayController,
788
+ {
789
+ isOpen,
790
+ controller: Controller,
791
+ overlayId: currentOverlayId,
792
+ overlayDispatch
793
+ },
794
+ componentKey
795
+ );
796
+ }
797
+ })
798
+ ] }) }) });
799
+ }
800
+ return {
801
+ overlay: overlay2,
802
+ OverlayProvider: OverlayProvider2,
803
+ useCurrentOverlay: useCurrentOverlay2,
804
+ useOverlayData: useOverlayData2
805
+ };
806
+ }
807
+
808
+ // src/utils/create-overlay-context.tsx
809
+ var { overlay, OverlayProvider, useCurrentOverlay, useOverlayData } = createOverlayProvider();
810
+ function experimental_createOverlayContext() {
811
+ return createOverlayProvider();
812
+ }
813
+ export {
814
+ OverlayProvider,
815
+ createUseExternalEvents,
816
+ experimental_createOverlayContext,
817
+ overlay,
818
+ useCurrentOverlay,
819
+ useOverlayData
820
+ };
821
+ //# sourceMappingURL=index.mjs.map