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.
- package/lib/commonjs/BottomSheetHost.js +29 -26
- package/lib/commonjs/BottomSheetHost.js.map +1 -1
- package/lib/commonjs/BottomSheetManaged.js +1 -1
- package/lib/commonjs/BottomSheetManaged.js.map +1 -1
- package/lib/commonjs/BottomSheetPortal.js +2 -3
- package/lib/commonjs/BottomSheetPortal.js.map +1 -1
- package/lib/commonjs/bottomSheet.store.js +16 -0
- package/lib/commonjs/bottomSheet.store.js.map +1 -1
- package/lib/commonjs/bottomSheetCoordinator.js +2 -2
- package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
- package/lib/commonjs/index.js +17 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/refsMap.js +13 -2
- package/lib/commonjs/refsMap.js.map +1 -1
- package/lib/commonjs/useBottomSheetControl.js +47 -62
- package/lib/commonjs/useBottomSheetControl.js.map +1 -1
- package/lib/commonjs/useBottomSheetManager.js +22 -18
- package/lib/commonjs/useBottomSheetManager.js.map +1 -1
- package/lib/commonjs/useBottomSheetState.js +12 -4
- package/lib/commonjs/useBottomSheetState.js.map +1 -1
- package/lib/commonjs/useBottomSheetStatus.js +35 -0
- package/lib/commonjs/useBottomSheetStatus.js.map +1 -0
- package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetPortal.d.ts.map +1 -1
- package/lib/typescript/src/bottomSheet.store.d.ts +1 -0
- package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -6
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/refsMap.d.ts +6 -1
- package/lib/typescript/src/refsMap.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetControl.d.ts +1 -3
- package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetManager.d.ts +10 -1
- package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetState.d.ts +11 -7
- package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetStatus.d.ts +8 -0
- package/lib/typescript/src/useBottomSheetStatus.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/BottomSheetHost.tsx +5 -3
- package/src/BottomSheetManaged.tsx +2 -2
- package/src/BottomSheetPortal.tsx +6 -5
- package/src/bottomSheet.store.ts +24 -0
- package/src/bottomSheetCoordinator.ts +3 -3
- package/src/index.tsx +27 -6
- package/src/refsMap.ts +16 -4
- package/src/useBottomSheetControl.ts +3 -15
- package/src/useBottomSheetManager.tsx +15 -9
- package/src/useBottomSheetState.ts +19 -17
- 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 {
|
|
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
|
-
|
|
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 {
|
|
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,
|
|
12
|
+
const { storeOpen, startClosing, storeClearGroup } = useBottomSheetStore(
|
|
13
13
|
(store) => ({
|
|
14
14
|
storeOpen: store.open,
|
|
15
|
-
|
|
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
|
-
|
|
36
|
+
setSheetRef(id, ref);
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
59
|
-
|
|
59
|
+
const clear = () => {
|
|
60
|
+
const groupId = bottomSheetManagerContext?.groupId || 'default';
|
|
61
|
+
storeClearGroup(groupId);
|
|
60
62
|
};
|
|
61
63
|
|
|
62
64
|
return {
|
|
63
|
-
|
|
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
|
-
|
|
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:
|
|
13
|
+
params: TParams;
|
|
24
14
|
close: () => void;
|
|
15
|
+
/** @deprecated Use `close` instead */
|
|
25
16
|
closeBottomSheet: () => void;
|
|
26
17
|
}
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
'
|
|
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
|
|
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
|
+
}
|