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.
- package/README.md +7 -3
- package/lib/commonjs/BottomSheetHost.js +135 -105
- 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/BottomSheetScaleView.js +23 -14
- package/lib/commonjs/BottomSheetScaleView.js.map +1 -1
- package/lib/commonjs/bottomSheet.store.js +19 -55
- 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 +57 -65
- package/lib/commonjs/useBottomSheetControl.js.map +1 -1
- package/lib/commonjs/useBottomSheetManager.js +33 -48
- 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/commonjs/useScaleAnimation.js +15 -10
- package/lib/commonjs/useScaleAnimation.js.map +1 -1
- package/lib/typescript/example/src/App.d.ts.map +1 -1
- package/lib/typescript/example/src/components/Badge.d.ts +9 -0
- package/lib/typescript/example/src/components/Badge.d.ts.map +1 -0
- package/lib/typescript/example/src/components/Button.d.ts +14 -0
- package/lib/typescript/example/src/components/Button.d.ts.map +1 -0
- package/lib/typescript/example/src/components/DemoCard.d.ts +14 -0
- package/lib/typescript/example/src/components/DemoCard.d.ts.map +1 -0
- package/lib/typescript/example/src/components/Sheet.d.ts +14 -0
- package/lib/typescript/example/src/components/Sheet.d.ts.map +1 -0
- package/lib/typescript/example/src/components/index.d.ts +5 -0
- package/lib/typescript/example/src/components/index.d.ts.map +1 -0
- package/lib/typescript/example/src/context/UserContext.d.ts +13 -0
- package/lib/typescript/example/src/context/UserContext.d.ts.map +1 -0
- package/lib/typescript/example/src/context/index.d.ts +2 -0
- package/lib/typescript/example/src/context/index.d.ts.map +1 -0
- package/lib/typescript/example/src/screens/HomeScreen.d.ts +2 -0
- package/lib/typescript/example/src/screens/HomeScreen.d.ts.map +1 -0
- package/lib/typescript/example/src/screens/index.d.ts +2 -0
- package/lib/typescript/example/src/screens/index.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/ContextSheets.d.ts +10 -0
- package/lib/typescript/example/src/sheets/ContextSheets.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/DynamicContentSheet.d.ts +3 -0
- package/lib/typescript/example/src/sheets/DynamicContentSheet.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/NavigationSheets.d.ts +6 -0
- package/lib/typescript/example/src/sheets/NavigationSheets.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/NestedScaleSheets.d.ts +5 -0
- package/lib/typescript/example/src/sheets/NestedScaleSheets.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/PortalModeSheets.d.ts +4 -0
- package/lib/typescript/example/src/sheets/PortalModeSheets.d.ts.map +1 -0
- package/lib/typescript/example/src/sheets/index.d.ts +6 -0
- package/lib/typescript/example/src/sheets/index.d.ts.map +1 -0
- package/lib/typescript/example/src/styles/index.d.ts +2 -0
- package/lib/typescript/example/src/styles/index.d.ts.map +1 -0
- package/lib/typescript/example/src/styles/theme.d.ts +164 -0
- package/lib/typescript/example/src/styles/theme.d.ts.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/BottomSheetScaleView.d.ts.map +1 -1
- package/lib/typescript/src/bottomSheet.store.d.ts +2 -8
- 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 +7 -4
- package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetManager.d.ts +10 -17
- 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/lib/typescript/src/useScaleAnimation.d.ts +4 -1
- package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BottomSheetHost.tsx +12 -14
- package/src/BottomSheetManaged.tsx +2 -2
- package/src/BottomSheetPortal.tsx +6 -5
- package/src/BottomSheetScaleView.tsx +2 -3
- package/src/bottomSheet.store.ts +28 -65
- package/src/bottomSheetCoordinator.ts +3 -3
- package/src/index.tsx +27 -6
- package/src/refsMap.ts +16 -4
- package/src/useBottomSheetControl.ts +22 -18
- package/src/useBottomSheetManager.tsx +25 -34
- package/src/useBottomSheetState.ts +19 -17
- package/src/useBottomSheetStatus.ts +25 -0
- 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 {
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
36
|
+
setSheetRef(id, ref);
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const contentWithRef = React.cloneElement(content, {
|
|
39
|
+
ref,
|
|
40
|
+
} as { ref: typeof ref });
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
72
|
-
|
|
59
|
+
const clear = () => {
|
|
60
|
+
const groupId = bottomSheetManagerContext?.groupId || 'default';
|
|
61
|
+
storeClearGroup(groupId);
|
|
73
62
|
};
|
|
74
63
|
|
|
75
64
|
return {
|
|
76
|
-
|
|
65
|
+
open: openBottomSheet,
|
|
77
66
|
close,
|
|
67
|
+
clear,
|
|
68
|
+
/** @deprecated Use `open` instead */
|
|
78
69
|
openBottomSheet,
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/useScaleAnimation.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
95
|
+
return withTiming(scaleDepth, { duration });
|
|
91
96
|
});
|
|
92
97
|
|
|
93
98
|
return useAnimatedStyle(() => {
|