react-native-bottom-sheet-stack 1.5.3 → 1.6.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/BottomSheetBackdrop.js.map +1 -1
- package/lib/commonjs/BottomSheetHost.js +103 -140
- package/lib/commonjs/BottomSheetHost.js.map +1 -1
- package/lib/commonjs/BottomSheetManaged.js +8 -9
- package/lib/commonjs/BottomSheetManaged.js.map +1 -1
- package/lib/commonjs/BottomSheetPortal.js +2 -10
- package/lib/commonjs/BottomSheetPortal.js.map +1 -1
- package/lib/commonjs/BottomSheetScaleView.js +13 -28
- package/lib/commonjs/BottomSheetScaleView.js.map +1 -1
- package/lib/commonjs/useBottomSheetContext.js +18 -11
- package/lib/commonjs/useBottomSheetContext.js.map +1 -1
- package/lib/commonjs/useBottomSheetControl.js.map +1 -1
- package/lib/commonjs/useScaleAnimation.js +38 -16
- package/lib/commonjs/useScaleAnimation.js.map +1 -1
- package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManaged.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/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetContext.d.ts +1 -2
- package/lib/typescript/src/useBottomSheetContext.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetControl.d.ts.map +1 -1
- package/lib/typescript/src/useScaleAnimation.d.ts +12 -5
- package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BottomSheetBackdrop.tsx +0 -3
- package/src/BottomSheetHost.tsx +17 -31
- package/src/BottomSheetManaged.tsx +3 -9
- package/src/BottomSheetPortal.tsx +4 -6
- package/src/BottomSheetScaleView.tsx +2 -7
- package/src/index.tsx +1 -1
- package/src/useBottomSheetContext.ts +13 -11
- package/src/useBottomSheetControl.ts +0 -1
- package/src/useScaleAnimation.ts +26 -17
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import { shallow } from 'zustand/shallow';
|
|
1
2
|
import { useMaybeBottomSheetContext } from './BottomSheet.context';
|
|
2
|
-
import {
|
|
3
|
-
useBottomSheetStore,
|
|
4
|
-
type BottomSheetState,
|
|
5
|
-
} from './bottomSheet.store';
|
|
3
|
+
import { useBottomSheetStore } from './bottomSheet.store';
|
|
6
4
|
import type {
|
|
7
5
|
BottomSheetPortalId,
|
|
8
6
|
BottomSheetPortalParams,
|
|
9
7
|
} from './portal.types';
|
|
10
8
|
|
|
11
9
|
export interface UseBottomSheetContextReturn<TParams> {
|
|
12
|
-
|
|
10
|
+
id: string;
|
|
13
11
|
params: TParams;
|
|
14
12
|
close: () => void;
|
|
15
13
|
/** @deprecated Use `close` instead */
|
|
@@ -27,23 +25,27 @@ export function useBottomSheetContext<
|
|
|
27
25
|
>(): UseBottomSheetContextReturn<BottomSheetPortalParams<T> | unknown> {
|
|
28
26
|
const context = useMaybeBottomSheetContext();
|
|
29
27
|
|
|
30
|
-
const
|
|
31
|
-
(state) =>
|
|
28
|
+
const { id, params } = useBottomSheetStore(
|
|
29
|
+
(state) => ({
|
|
30
|
+
id: state.sheetsById[context?.id!]?.id,
|
|
31
|
+
params: state.sheetsById[context?.id!]?.params,
|
|
32
|
+
}),
|
|
33
|
+
shallow
|
|
32
34
|
);
|
|
33
35
|
|
|
34
36
|
const startClosing = useBottomSheetStore((state) => state.startClosing);
|
|
35
37
|
|
|
36
|
-
if (!
|
|
38
|
+
if (!id) {
|
|
37
39
|
throw new Error(
|
|
38
40
|
'useBottomSheetContext must be used within a BottomSheet component'
|
|
39
41
|
);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const close = () => startClosing(
|
|
44
|
+
const close = () => startClosing(id);
|
|
43
45
|
|
|
44
46
|
return {
|
|
45
|
-
|
|
46
|
-
params:
|
|
47
|
+
id,
|
|
48
|
+
params: params as BottomSheetPortalParams<T>,
|
|
47
49
|
close,
|
|
48
50
|
closeBottomSheet: close,
|
|
49
51
|
};
|
|
@@ -48,7 +48,6 @@ export function useBottomSheetControl<T extends BottomSheetPortalId>(
|
|
|
48
48
|
const open = (options?: OpenOptions<T>) => {
|
|
49
49
|
const groupId = bottomSheetManagerContext?.groupId || 'default';
|
|
50
50
|
|
|
51
|
-
// Create ref when opening (same pattern as useBottomSheetManager)
|
|
52
51
|
const ref = React.createRef<BottomSheetMethods>();
|
|
53
52
|
setSheetRef(id, ref);
|
|
54
53
|
|
package/src/useScaleAnimation.ts
CHANGED
|
@@ -3,11 +3,19 @@ import {
|
|
|
3
3
|
useAnimatedStyle,
|
|
4
4
|
useDerivedValue,
|
|
5
5
|
withTiming,
|
|
6
|
+
withSpring,
|
|
7
|
+
type WithTimingConfig,
|
|
8
|
+
type WithSpringConfig,
|
|
6
9
|
} from 'react-native-reanimated';
|
|
7
10
|
import {
|
|
8
11
|
useBottomSheetStore,
|
|
9
12
|
type BottomSheetStore,
|
|
10
13
|
} from './bottomSheet.store';
|
|
14
|
+
import { useBottomSheetManagerContext } from './BottomSheetManager.provider';
|
|
15
|
+
|
|
16
|
+
export type ScaleAnimationConfig =
|
|
17
|
+
| { type: 'timing'; config?: WithTimingConfig }
|
|
18
|
+
| { type: 'spring'; config?: WithSpringConfig };
|
|
11
19
|
|
|
12
20
|
export interface ScaleConfig {
|
|
13
21
|
/** Scale factor when sheet is open (default: 0.92) */
|
|
@@ -16,16 +24,21 @@ export interface ScaleConfig {
|
|
|
16
24
|
translateY?: number;
|
|
17
25
|
/** Border radius when sheet is open (default: 12) */
|
|
18
26
|
borderRadius?: number;
|
|
19
|
-
/** Animation
|
|
20
|
-
|
|
27
|
+
/** Animation config - timing or spring (default: timing with 300ms duration) */
|
|
28
|
+
animation?: ScaleAnimationConfig;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
const
|
|
31
|
+
const DEFAULT_ANIMATION: ScaleAnimationConfig = {
|
|
32
|
+
type: 'timing',
|
|
33
|
+
config: { duration: 300 },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const DEFAULT_CONFIG = {
|
|
24
37
|
scale: 0.92,
|
|
25
38
|
translateY: 10,
|
|
26
39
|
borderRadius: 12,
|
|
27
|
-
|
|
28
|
-
}
|
|
40
|
+
animation: DEFAULT_ANIMATION,
|
|
41
|
+
} satisfies Required<ScaleConfig>;
|
|
29
42
|
|
|
30
43
|
/**
|
|
31
44
|
* Returns the number of sheets with scaleBackground above a given element.
|
|
@@ -39,12 +52,9 @@ export function useScaleDepth(groupId: string, sheetId?: string): number {
|
|
|
39
52
|
const scaleDepthSelector = (state: BottomSheetStore) => {
|
|
40
53
|
const { stackOrder, sheetsById } = state;
|
|
41
54
|
|
|
42
|
-
// For background: check if ANY scaleBackground sheet is active (binary 0/1)
|
|
43
|
-
// For a sheet: count scaleBackground sheets above it in the stack
|
|
44
55
|
const startIndex = sheetId ? stackOrder.indexOf(sheetId) + 1 : 0;
|
|
45
56
|
|
|
46
57
|
if (sheetId && startIndex === 0) {
|
|
47
|
-
// Sheet not found in stack, return previous value to avoid flicker
|
|
48
58
|
return prevDepthRef.current;
|
|
49
59
|
}
|
|
50
60
|
|
|
@@ -59,8 +69,6 @@ export function useScaleDepth(groupId: string, sheetId?: string): number {
|
|
|
59
69
|
sheet.status !== 'closing'
|
|
60
70
|
) {
|
|
61
71
|
depth++;
|
|
62
|
-
// For background wrapper (no sheetId), we only need to know if there's at least one
|
|
63
|
-
// Don't accumulate - background scales once, sheets below scale cumulatively
|
|
64
72
|
if (!sheetId) {
|
|
65
73
|
break;
|
|
66
74
|
}
|
|
@@ -78,21 +86,22 @@ export function useScaleDepth(groupId: string, sheetId?: string): number {
|
|
|
78
86
|
* Returns animated style for scale effect based on depth.
|
|
79
87
|
* Uses power scaling: scale^depth for cascading effect.
|
|
80
88
|
*/
|
|
81
|
-
export function useScaleAnimatedStyle(
|
|
82
|
-
{ groupId,
|
|
83
|
-
config?: ScaleConfig
|
|
84
|
-
) {
|
|
89
|
+
export function useScaleAnimatedStyle({ id }: { id?: string } = {}) {
|
|
90
|
+
const { groupId, scaleConfig } = useBottomSheetManagerContext();
|
|
85
91
|
const scaleDepth = useScaleDepth(groupId, id);
|
|
86
92
|
|
|
87
93
|
const {
|
|
88
94
|
scale = DEFAULT_CONFIG.scale,
|
|
89
95
|
translateY = DEFAULT_CONFIG.translateY,
|
|
90
96
|
borderRadius = DEFAULT_CONFIG.borderRadius,
|
|
91
|
-
|
|
92
|
-
} =
|
|
97
|
+
animation = DEFAULT_CONFIG.animation,
|
|
98
|
+
} = scaleConfig ?? {};
|
|
93
99
|
|
|
94
100
|
const progress = useDerivedValue(() => {
|
|
95
|
-
|
|
101
|
+
if (animation.type === 'spring') {
|
|
102
|
+
return withSpring(scaleDepth, animation.config);
|
|
103
|
+
}
|
|
104
|
+
return withTiming(scaleDepth, animation.config);
|
|
96
105
|
});
|
|
97
106
|
|
|
98
107
|
return useAnimatedStyle(() => {
|