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
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type OpenMode } from './bottomSheet.store';
|
|
3
3
|
export declare const useBottomSheetManager: () => {
|
|
4
|
-
|
|
4
|
+
open: (content: React.ReactElement, options?: {
|
|
5
|
+
id?: string;
|
|
6
|
+
groupId?: string;
|
|
7
|
+
mode?: OpenMode;
|
|
8
|
+
scaleBackground?: boolean;
|
|
9
|
+
}) => string;
|
|
5
10
|
close: (id: string) => void;
|
|
11
|
+
clear: () => void;
|
|
12
|
+
/** @deprecated Use `open` instead */
|
|
6
13
|
openBottomSheet: (content: React.ReactElement, options?: {
|
|
7
14
|
id?: string;
|
|
8
15
|
groupId?: string;
|
|
9
16
|
mode?: OpenMode;
|
|
10
17
|
scaleBackground?: boolean;
|
|
11
18
|
}) => string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
id: string;
|
|
15
|
-
content: React.ReactNode;
|
|
16
|
-
scaleBackground?: boolean | undefined;
|
|
17
|
-
usePortal?: boolean | undefined;
|
|
18
|
-
params?: Record<string, unknown> | undefined;
|
|
19
|
-
}) => void;
|
|
20
|
-
replaceBottomSheet: (sheet: {
|
|
21
|
-
groupId: string;
|
|
22
|
-
id: string;
|
|
23
|
-
content: React.ReactNode;
|
|
24
|
-
scaleBackground?: boolean | undefined;
|
|
25
|
-
usePortal?: boolean | undefined;
|
|
26
|
-
params?: Record<string, unknown> | undefined;
|
|
27
|
-
}) => void;
|
|
19
|
+
/** @deprecated Use `clear` instead */
|
|
20
|
+
clearAll: () => void;
|
|
28
21
|
};
|
|
29
22
|
//# sourceMappingURL=useBottomSheetManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBottomSheetManager.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAuB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAMzE,eAAO,MAAM,qBAAqB;;
|
|
1
|
+
{"version":3,"file":"useBottomSheetManager.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAuB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAMzE,eAAO,MAAM,qBAAqB;oBAarB,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;gBA2BgB,MAAM;;IAavB,qCAAqC;+BA9C5B,KAAK,CAAC,YAAY,YAClB;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;IA0CD,sCAAsC;;CAGzC,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { type BottomSheetState } from './bottomSheet.store';
|
|
2
2
|
import type { BottomSheetPortalId, BottomSheetPortalParams } from './portal.types';
|
|
3
|
-
|
|
4
|
-
type Unspecified = typeof UNSPECIFIED;
|
|
5
|
-
type ResolveParams<T> = T extends Unspecified ? unknown : T extends BottomSheetPortalId ? BottomSheetPortalParams<T> : unknown;
|
|
6
|
-
export interface UseBottomSheetStateReturn<T> {
|
|
3
|
+
export interface UseBottomSheetContextReturn<TParams> {
|
|
7
4
|
bottomSheetState: BottomSheetState;
|
|
8
|
-
params:
|
|
5
|
+
params: TParams;
|
|
9
6
|
close: () => void;
|
|
7
|
+
/** @deprecated Use `close` instead */
|
|
10
8
|
closeBottomSheet: () => void;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
export
|
|
10
|
+
/** Without generic - params typed as unknown */
|
|
11
|
+
export declare function useBottomSheetContext(): UseBottomSheetContextReturn<unknown>;
|
|
12
|
+
/** With generic - params typed based on portal registry */
|
|
13
|
+
export declare function useBottomSheetContext<T extends BottomSheetPortalId>(): UseBottomSheetContextReturn<BottomSheetPortalParams<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `useBottomSheetContext` instead
|
|
16
|
+
*/
|
|
17
|
+
export declare const useBottomSheetState: typeof useBottomSheetContext;
|
|
14
18
|
//# sourceMappingURL=useBottomSheetState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBottomSheetState.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetState.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useBottomSheetState.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetState.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,2BAA2B,CAAC,OAAO;IAClD,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,sCAAsC;IACtC,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,gDAAgD;AAChD,wBAAgB,qBAAqB,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;AAC9E,2DAA2D;AAC3D,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,mBAAmB,KAC1B,2BAA2B,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AA4B7D;;GAEG;AACH,eAAO,MAAM,mBAAmB,8BAAwB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BottomSheetStatus } from './bottomSheet.store';
|
|
2
|
+
import type { BottomSheetPortalId } from './portal.types';
|
|
3
|
+
export interface UseBottomSheetStatusReturn {
|
|
4
|
+
status: BottomSheetStatus | null;
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function useBottomSheetStatus(id: BottomSheetPortalId): UseBottomSheetStatusReturn;
|
|
8
|
+
//# sourceMappingURL=useBottomSheetStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetStatus.d.ts","sourceRoot":"","sources":["../../../src/useBottomSheetStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,mBAAmB,GACtB,0BAA0B,CAW5B"}
|
|
@@ -19,7 +19,10 @@ export declare function useScaleDepth(groupId: string, sheetId?: string): number
|
|
|
19
19
|
* Returns animated style for scale effect based on depth.
|
|
20
20
|
* Uses power scaling: scale^depth for cascading effect.
|
|
21
21
|
*/
|
|
22
|
-
export declare function useScaleAnimatedStyle(
|
|
22
|
+
export declare function useScaleAnimatedStyle({ groupId, id }: {
|
|
23
|
+
groupId: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
}, config?: ScaleConfig): {
|
|
23
26
|
transform: ({
|
|
24
27
|
scale: number;
|
|
25
28
|
translateY?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScaleAnimation.d.ts","sourceRoot":"","sources":["../../../src/useScaleAnimation.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AASD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCvE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"useScaleAnimation.d.ts","sourceRoot":"","sources":["../../../src/useScaleAnimation.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AASD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCvE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EACjD,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;EAoCrB"}
|
package/package.json
CHANGED
package/src/BottomSheetHost.tsx
CHANGED
|
@@ -6,16 +6,13 @@ import { PortalHost } from 'react-native-teleport';
|
|
|
6
6
|
|
|
7
7
|
import { shallow } from 'zustand/shallow';
|
|
8
8
|
import { cleanupAnimatedIndex } from './animatedRegistry';
|
|
9
|
-
import {
|
|
9
|
+
import { cleanupSheetRef } from './refsMap';
|
|
10
10
|
import { BottomSheetContext } from './BottomSheet.context';
|
|
11
11
|
import { useBottomSheetStore } from './bottomSheet.store';
|
|
12
|
-
import {
|
|
12
|
+
import { BottomSheetBackdrop } from './BottomSheetBackdrop';
|
|
13
13
|
import { initBottomSheetCoordinator } from './bottomSheetCoordinator';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
useScaleDepth,
|
|
17
|
-
type ScaleConfig,
|
|
18
|
-
} from './useScaleAnimation';
|
|
14
|
+
import { useBottomSheetManagerContext } from './BottomSheetManager.provider';
|
|
15
|
+
import { useScaleAnimatedStyle, type ScaleConfig } from './useScaleAnimation';
|
|
19
16
|
|
|
20
17
|
function PortalHostWrapper({
|
|
21
18
|
id,
|
|
@@ -27,7 +24,7 @@ function PortalHostWrapper({
|
|
|
27
24
|
height: number;
|
|
28
25
|
}) {
|
|
29
26
|
return (
|
|
30
|
-
<View style={{ flex: 1, width, height }}>
|
|
27
|
+
<View style={{ flex: 1, width, height }} pointerEvents="box-none">
|
|
31
28
|
<PortalHost name={`bottomsheet-${id}`} style={{ width, height }} />
|
|
32
29
|
</View>
|
|
33
30
|
);
|
|
@@ -35,7 +32,7 @@ function PortalHostWrapper({
|
|
|
35
32
|
|
|
36
33
|
function BottomSheetHostComp() {
|
|
37
34
|
const queueIds = useQueueIds();
|
|
38
|
-
const
|
|
35
|
+
const clearGroup = useBottomSheetStore((store) => store.clearGroup);
|
|
39
36
|
|
|
40
37
|
const { groupId, scaleConfig } = useBottomSheetManagerContext();
|
|
41
38
|
|
|
@@ -48,9 +45,9 @@ function BottomSheetHostComp() {
|
|
|
48
45
|
|
|
49
46
|
useEffect(() => {
|
|
50
47
|
return () => {
|
|
51
|
-
|
|
48
|
+
clearGroup(groupId);
|
|
52
49
|
};
|
|
53
|
-
}, [
|
|
50
|
+
}, [clearGroup, groupId]);
|
|
54
51
|
|
|
55
52
|
return (
|
|
56
53
|
<>
|
|
@@ -79,15 +76,16 @@ function QueueItem({
|
|
|
79
76
|
stackIndex: number;
|
|
80
77
|
}) {
|
|
81
78
|
const sheet = useBottomSheetStore((state) => state.sheetsById[id]);
|
|
79
|
+
const startClosing = useBottomSheetStore((state) => state.startClosing);
|
|
82
80
|
|
|
83
81
|
const { width, height } = useSafeAreaFrame();
|
|
84
82
|
const value = { id };
|
|
85
83
|
|
|
86
|
-
const
|
|
87
|
-
const scaleStyle = useScaleAnimatedStyle(scaleDepth, scaleConfig);
|
|
84
|
+
const scaleStyle = useScaleAnimatedStyle({ groupId, id }, scaleConfig);
|
|
88
85
|
|
|
89
86
|
useEffect(() => {
|
|
90
87
|
return () => {
|
|
88
|
+
cleanupSheetRef(id);
|
|
91
89
|
cleanupAnimatedIndex(id);
|
|
92
90
|
};
|
|
93
91
|
}, [id]);
|
|
@@ -98,7 +96,7 @@ function QueueItem({
|
|
|
98
96
|
return (
|
|
99
97
|
<BottomSheetContext.Provider value={value}>
|
|
100
98
|
<View style={[StyleSheet.absoluteFillObject, { zIndex: backdropZIndex }]}>
|
|
101
|
-
<BottomSheetBackdrop sheetId={id} />
|
|
99
|
+
<BottomSheetBackdrop sheetId={id} onPress={() => startClosing(id)} />
|
|
102
100
|
</View>
|
|
103
101
|
|
|
104
102
|
{/* Sheet content - rendered with scaling */}
|
|
@@ -7,7 +7,7 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { getAnimatedIndex } from './animatedRegistry';
|
|
9
9
|
import { createSheetEventHandlers } from './bottomSheetCoordinator';
|
|
10
|
-
import {
|
|
10
|
+
import { useBottomSheetContext } from './useBottomSheetState';
|
|
11
11
|
|
|
12
12
|
export interface BottomSheetRef extends BottomSheetMethods {}
|
|
13
13
|
|
|
@@ -32,7 +32,7 @@ export const BottomSheetManaged = React.forwardRef<
|
|
|
32
32
|
},
|
|
33
33
|
ref
|
|
34
34
|
) => {
|
|
35
|
-
const { bottomSheetState } =
|
|
35
|
+
const { bottomSheetState } = useBottomSheetContext();
|
|
36
36
|
|
|
37
37
|
// Get or create shared animated index for this sheet
|
|
38
38
|
const animatedIndex =
|
|
@@ -6,7 +6,7 @@ import { Portal } from 'react-native-teleport';
|
|
|
6
6
|
import { BottomSheetContext } from './BottomSheet.context';
|
|
7
7
|
import { useBottomSheetStore } from './bottomSheet.store';
|
|
8
8
|
import type { BottomSheetPortalId } from './portal.types';
|
|
9
|
-
import {
|
|
9
|
+
import { getSheetRef } from './refsMap';
|
|
10
10
|
|
|
11
11
|
interface BottomSheetPortalProps {
|
|
12
12
|
id: BottomSheetPortalId;
|
|
@@ -22,13 +22,14 @@ export function BottomSheetPortal({ id, children }: BottomSheetPortalProps) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Get the ref that was created in useBottomSheetControl.open()
|
|
25
|
-
const ref =
|
|
25
|
+
const ref = getSheetRef(id);
|
|
26
26
|
|
|
27
27
|
// Clone the child element to add the ref
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const childWithRef = React.cloneElement(children, {
|
|
29
|
+
ref,
|
|
30
|
+
} as { ref: typeof ref });
|
|
30
31
|
|
|
31
|
-
// Wrap with BottomSheetContext so
|
|
32
|
+
// Wrap with BottomSheetContext so useBottomSheetContext() works inside portal content
|
|
32
33
|
return (
|
|
33
34
|
<Portal hostName={`bottomsheet-${id}`}>
|
|
34
35
|
<BottomSheetContext.Provider value={{ id }}>
|
|
@@ -2,7 +2,7 @@ import { useContext, type PropsWithChildren } from 'react';
|
|
|
2
2
|
import { StyleSheet } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
4
|
import { BottomSheetManagerContext } from './BottomSheetManager.context';
|
|
5
|
-
import { useScaleAnimatedStyle
|
|
5
|
+
import { useScaleAnimatedStyle } from './useScaleAnimation';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Wraps your app content with iOS-style scale animation when a bottom sheet
|
|
@@ -24,8 +24,7 @@ export function BottomSheetScaleView({ children }: PropsWithChildren) {
|
|
|
24
24
|
const groupId = context?.groupId ?? 'default';
|
|
25
25
|
const scaleConfig = context?.scaleConfig;
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
const animatedStyle = useScaleAnimatedStyle(scaleDepth, scaleConfig);
|
|
27
|
+
const animatedStyle = useScaleAnimatedStyle({ groupId }, scaleConfig);
|
|
29
28
|
|
|
30
29
|
return (
|
|
31
30
|
<Animated.View style={[styles.container, animatedStyle]}>
|
package/src/bottomSheet.store.ts
CHANGED
|
@@ -22,20 +22,13 @@ interface BottomSheetStoreState {
|
|
|
22
22
|
stackOrder: string[];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export interface PortalOpenOptions<TParams = Record<string, unknown>> {
|
|
26
|
-
scaleBackground?: boolean;
|
|
27
|
-
params?: TParams;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
25
|
interface BottomSheetStoreActions {
|
|
31
|
-
|
|
32
|
-
switch(sheet: TriggerState): void;
|
|
33
|
-
replace(sheet: TriggerState): void;
|
|
34
|
-
openPortal(id: string, groupId: string, options?: PortalOpenOptions): void;
|
|
26
|
+
open(sheet: TriggerState, mode?: OpenMode): void;
|
|
35
27
|
markOpen(id: string): void;
|
|
36
28
|
startClosing(id: string): void;
|
|
37
29
|
finishClosing(id: string): void;
|
|
38
30
|
updateParams(id: string, params: Record<string, unknown> | undefined): void;
|
|
31
|
+
clearGroup(groupId: string): void;
|
|
39
32
|
clearAll(): void;
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -46,21 +39,7 @@ export const useBottomSheetStore = create(
|
|
|
46
39
|
sheetsById: {},
|
|
47
40
|
stackOrder: [],
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
set((state) => {
|
|
51
|
-
if (state.sheetsById[sheet.id]) {
|
|
52
|
-
return state;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
sheetsById: {
|
|
56
|
-
...state.sheetsById,
|
|
57
|
-
[sheet.id]: { ...sheet, status: 'opening' },
|
|
58
|
-
},
|
|
59
|
-
stackOrder: [...state.stackOrder, sheet.id],
|
|
60
|
-
};
|
|
61
|
-
}),
|
|
62
|
-
|
|
63
|
-
switch: (sheet) =>
|
|
42
|
+
open: (sheet, mode = 'push') =>
|
|
64
43
|
set((state) => {
|
|
65
44
|
if (state.sheetsById[sheet.id]) {
|
|
66
45
|
return state;
|
|
@@ -69,31 +48,14 @@ export const useBottomSheetStore = create(
|
|
|
69
48
|
const newSheetsById = { ...state.sheetsById };
|
|
70
49
|
const topId = state.stackOrder[state.stackOrder.length - 1];
|
|
71
50
|
|
|
72
|
-
if (topId && newSheetsById[topId]) {
|
|
51
|
+
if (mode === 'switch' && topId && newSheetsById[topId]) {
|
|
73
52
|
newSheetsById[topId] = {
|
|
74
53
|
...newSheetsById[topId],
|
|
75
54
|
status: 'hidden',
|
|
76
55
|
};
|
|
77
56
|
}
|
|
78
57
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
sheetsById: newSheetsById,
|
|
83
|
-
stackOrder: [...state.stackOrder, sheet.id],
|
|
84
|
-
};
|
|
85
|
-
}),
|
|
86
|
-
|
|
87
|
-
replace: (sheet) =>
|
|
88
|
-
set((state) => {
|
|
89
|
-
if (state.sheetsById[sheet.id]) {
|
|
90
|
-
return state;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const newSheetsById = { ...state.sheetsById };
|
|
94
|
-
const topId = state.stackOrder[state.stackOrder.length - 1];
|
|
95
|
-
|
|
96
|
-
if (topId && newSheetsById[topId]) {
|
|
58
|
+
if (mode === 'replace' && topId && newSheetsById[topId]) {
|
|
97
59
|
newSheetsById[topId] = {
|
|
98
60
|
...newSheetsById[topId],
|
|
99
61
|
status: 'closing',
|
|
@@ -108,28 +70,6 @@ export const useBottomSheetStore = create(
|
|
|
108
70
|
};
|
|
109
71
|
}),
|
|
110
72
|
|
|
111
|
-
openPortal: (id, groupId, options) =>
|
|
112
|
-
set((state) => {
|
|
113
|
-
if (state.sheetsById[id]) {
|
|
114
|
-
return state;
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
sheetsById: {
|
|
118
|
-
...state.sheetsById,
|
|
119
|
-
[id]: {
|
|
120
|
-
id,
|
|
121
|
-
groupId,
|
|
122
|
-
content: null,
|
|
123
|
-
status: 'opening',
|
|
124
|
-
usePortal: true,
|
|
125
|
-
scaleBackground: options?.scaleBackground,
|
|
126
|
-
params: options?.params,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
stackOrder: [...state.stackOrder, id],
|
|
130
|
-
};
|
|
131
|
-
}),
|
|
132
|
-
|
|
133
73
|
markOpen: (id) =>
|
|
134
74
|
set((state) => {
|
|
135
75
|
const sheet = state.sheetsById[id];
|
|
@@ -205,6 +145,29 @@ export const useBottomSheetStore = create(
|
|
|
205
145
|
};
|
|
206
146
|
}),
|
|
207
147
|
|
|
148
|
+
clearGroup: (groupId) =>
|
|
149
|
+
set((state) => {
|
|
150
|
+
const idsToRemove = new Set(
|
|
151
|
+
state.stackOrder.filter(
|
|
152
|
+
(id) => state.sheetsById[id]?.groupId === groupId
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (idsToRemove.size === 0) {
|
|
157
|
+
return state;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const newSheetsById = { ...state.sheetsById };
|
|
161
|
+
idsToRemove.forEach((id) => {
|
|
162
|
+
delete newSheetsById[id];
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
sheetsById: newSheetsById,
|
|
167
|
+
stackOrder: state.stackOrder.filter((id) => !idsToRemove.has(id)),
|
|
168
|
+
};
|
|
169
|
+
}),
|
|
170
|
+
|
|
208
171
|
clearAll: () => set(() => ({ sheetsById: {}, stackOrder: [] })),
|
|
209
172
|
}))
|
|
210
173
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useBottomSheetStore } from './bottomSheet.store';
|
|
2
|
-
import {
|
|
2
|
+
import { getSheetRef } from './refsMap';
|
|
3
3
|
|
|
4
4
|
export function initBottomSheetCoordinator(groupId: string) {
|
|
5
5
|
return useBottomSheetStore.subscribe(
|
|
@@ -15,12 +15,12 @@ export function initBottomSheetCoordinator(groupId: string) {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const ref =
|
|
18
|
+
const ref = getSheetRef(id)?.current;
|
|
19
19
|
|
|
20
20
|
switch (status) {
|
|
21
21
|
case 'opening':
|
|
22
22
|
requestAnimationFrame(() => {
|
|
23
|
-
|
|
23
|
+
getSheetRef(id)?.current?.expand();
|
|
24
24
|
});
|
|
25
25
|
break;
|
|
26
26
|
case 'hidden':
|
package/src/index.tsx
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
// Components
|
|
2
2
|
export { BottomSheetManagerProvider } from './BottomSheetManager.provider';
|
|
3
|
-
export {
|
|
4
|
-
export { useBottomSheetState } from './useBottomSheetState';
|
|
5
|
-
export { BottomSheetManaged } from './BottomSheetManaged';
|
|
3
|
+
export { BottomSheetHost } from './BottomSheetHost';
|
|
6
4
|
export { BottomSheetScaleView } from './BottomSheetScaleView';
|
|
7
|
-
export { type
|
|
5
|
+
export { BottomSheetManaged, type BottomSheetRef } from './BottomSheetManaged';
|
|
8
6
|
export { BottomSheetPortal } from './BottomSheetPortal';
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
// Hooks
|
|
9
|
+
export { useBottomSheetManager } from './useBottomSheetManager';
|
|
10
|
+
export {
|
|
11
|
+
useBottomSheetControl,
|
|
12
|
+
type UseBottomSheetControlReturn,
|
|
13
|
+
} from './useBottomSheetControl';
|
|
14
|
+
export {
|
|
15
|
+
useBottomSheetContext,
|
|
16
|
+
useBottomSheetState,
|
|
17
|
+
type UseBottomSheetContextReturn,
|
|
18
|
+
} from './useBottomSheetState';
|
|
19
|
+
export {
|
|
20
|
+
useBottomSheetStatus,
|
|
21
|
+
type UseBottomSheetStatusReturn,
|
|
22
|
+
} from './useBottomSheetStatus';
|
|
23
|
+
|
|
24
|
+
// Types
|
|
25
|
+
export type { ScaleConfig } from './useScaleAnimation';
|
|
26
|
+
export type {
|
|
27
|
+
BottomSheetStatus,
|
|
28
|
+
OpenMode,
|
|
29
|
+
BottomSheetState,
|
|
30
|
+
} from './bottomSheet.store';
|
|
10
31
|
export type {
|
|
11
32
|
BottomSheetPortalRegistry,
|
|
12
33
|
BottomSheetPortalId,
|
package/src/refsMap.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
|
|
2
|
+
import type { RefObject } from 'react';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type SheetRef = RefObject<BottomSheetMethods | null>;
|
|
5
|
+
|
|
6
|
+
const sheetRefsMap = new Map<string, SheetRef>();
|
|
7
|
+
|
|
8
|
+
export function getSheetRef(sheetId: string): SheetRef | undefined {
|
|
9
|
+
return sheetRefsMap.get(sheetId);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function setSheetRef(sheetId: string, ref: SheetRef): void {
|
|
13
|
+
sheetRefsMap.set(sheetId, ref);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function cleanupSheetRef(sheetId: string): void {
|
|
17
|
+
sheetRefsMap.delete(sheetId);
|
|
18
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
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 PortalOpenOptions,
|
|
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';
|
|
12
|
+
|
|
13
|
+
interface BaseOpenOptions<TParams> {
|
|
14
|
+
mode?: OpenMode;
|
|
15
|
+
scaleBackground?: boolean;
|
|
16
|
+
params?: TParams;
|
|
17
|
+
}
|
|
16
18
|
|
|
17
19
|
type OpenOptions<T extends BottomSheetPortalId> = Omit<
|
|
18
|
-
|
|
20
|
+
BaseOpenOptions<BottomSheetPortalParams<T>>,
|
|
19
21
|
'params'
|
|
20
22
|
> &
|
|
21
23
|
(HasParams<T> extends true
|
|
@@ -32,8 +34,6 @@ export interface UseBottomSheetControlReturn<T extends BottomSheetPortalId> {
|
|
|
32
34
|
close: () => void;
|
|
33
35
|
updateParams: (params: BottomSheetPortalParams<T>) => void;
|
|
34
36
|
resetParams: () => void;
|
|
35
|
-
isOpen: boolean;
|
|
36
|
-
status: BottomSheetStatus | null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function useBottomSheetControl<T extends BottomSheetPortalId>(
|
|
@@ -41,19 +41,28 @@ export function useBottomSheetControl<T extends BottomSheetPortalId>(
|
|
|
41
41
|
): UseBottomSheetControlReturn<T> {
|
|
42
42
|
const bottomSheetManagerContext = useMaybeBottomSheetManagerContext();
|
|
43
43
|
|
|
44
|
-
const
|
|
44
|
+
const storeOpen = useBottomSheetStore((state) => state.open);
|
|
45
45
|
const startClosing = useBottomSheetStore((state) => state.startClosing);
|
|
46
46
|
const storeUpdateParams = useBottomSheetStore((state) => state.updateParams);
|
|
47
|
-
const sheetState = useBottomSheetStore((state) => state.sheetsById[id]);
|
|
48
47
|
|
|
49
48
|
const open = (options?: OpenOptions<T>) => {
|
|
50
49
|
const groupId = bottomSheetManagerContext?.groupId || 'default';
|
|
51
50
|
|
|
52
51
|
// Create ref when opening (same pattern as useBottomSheetManager)
|
|
53
52
|
const ref = React.createRef<BottomSheetMethods>();
|
|
54
|
-
|
|
53
|
+
setSheetRef(id, ref);
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
storeOpen(
|
|
56
|
+
{
|
|
57
|
+
id,
|
|
58
|
+
groupId,
|
|
59
|
+
content: null,
|
|
60
|
+
usePortal: true,
|
|
61
|
+
scaleBackground: options?.scaleBackground,
|
|
62
|
+
params: options?.params as Record<string, unknown>,
|
|
63
|
+
},
|
|
64
|
+
options?.mode
|
|
65
|
+
);
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
const close = () => {
|
|
@@ -68,15 +77,10 @@ export function useBottomSheetControl<T extends BottomSheetPortalId>(
|
|
|
68
77
|
storeUpdateParams(id, undefined);
|
|
69
78
|
};
|
|
70
79
|
|
|
71
|
-
const status = sheetState?.status ?? null;
|
|
72
|
-
const isOpen = status === 'open' || status === 'opening';
|
|
73
|
-
|
|
74
80
|
return {
|
|
75
81
|
open: open as OpenFunction<T>,
|
|
76
82
|
close,
|
|
77
83
|
updateParams,
|
|
78
84
|
resetParams,
|
|
79
|
-
isOpen,
|
|
80
|
-
status,
|
|
81
85
|
};
|
|
82
86
|
}
|