react-native-bottom-sheet-stack 1.0.1 → 1.0.3
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/BottomSheet.context.js.map +1 -1
- package/lib/commonjs/BottomSheetBackdrop.js +76 -0
- package/lib/commonjs/BottomSheetBackdrop.js.map +1 -0
- package/lib/commonjs/BottomSheetHost.js +215 -51
- package/lib/commonjs/BottomSheetHost.js.map +1 -1
- package/lib/commonjs/BottomSheetManaged.js +128 -38
- package/lib/commonjs/BottomSheetManaged.js.map +1 -1
- package/lib/commonjs/BottomSheetManager.context.js.map +1 -1
- package/lib/commonjs/BottomSheetManager.provider.js +38 -13
- package/lib/commonjs/BottomSheetManager.provider.js.map +1 -1
- package/lib/commonjs/BottomSheetScaleView.js +67 -0
- package/lib/commonjs/BottomSheetScaleView.js.map +1 -0
- package/lib/commonjs/animatedRegistry.js +25 -0
- package/lib/commonjs/animatedRegistry.js.map +1 -0
- package/lib/commonjs/bottomSheet.store.js +86 -73
- package/lib/commonjs/bottomSheet.store.js.map +1 -1
- package/lib/commonjs/bottomSheetCoordinator.js +12 -14
- package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
- package/lib/commonjs/index.js +3 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/useBottomSheetManager.js +88 -44
- package/lib/commonjs/useBottomSheetManager.js.map +1 -1
- package/lib/commonjs/useBottomSheetState.js +40 -17
- package/lib/commonjs/useBottomSheetState.js.map +1 -1
- package/lib/commonjs/useScaleAnimation.js +108 -0
- package/lib/commonjs/useScaleAnimation.js.map +1 -0
- package/lib/typescript/example/src/App.d.ts +0 -2
- package/lib/typescript/example/src/App.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetBackdrop.d.ts +12 -0
- package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -0
- package/lib/typescript/src/BottomSheetHost.d.ts +2 -6
- package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManaged.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManager.context.d.ts +2 -0
- package/lib/typescript/src/BottomSheetManager.context.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManager.provider.d.ts +4 -3
- package/lib/typescript/src/BottomSheetManager.provider.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetScaleView.d.ts +18 -0
- package/lib/typescript/src/BottomSheetScaleView.d.ts.map +1 -0
- package/lib/typescript/src/animatedRegistry.d.ts +4 -0
- package/lib/typescript/src/animatedRegistry.d.ts.map +1 -0
- package/lib/typescript/src/bottomSheet.store.d.ts +6 -4
- package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
- package/lib/typescript/src/bottomSheetCoordinator.d.ts +1 -1
- package/lib/typescript/src/bottomSheetCoordinator.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
- package/lib/typescript/src/useScaleAnimation.d.ts +43 -0
- package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -0
- package/package.json +9 -2
- package/src/BottomSheetBackdrop.tsx +61 -0
- package/src/BottomSheetHost.tsx +89 -51
- package/src/BottomSheetManaged.tsx +26 -33
- package/src/BottomSheetManager.context.tsx +2 -0
- package/src/BottomSheetManager.provider.tsx +10 -6
- package/src/BottomSheetScaleView.tsx +41 -0
- package/src/animatedRegistry.ts +22 -0
- package/src/bottomSheet.store.ts +132 -97
- package/src/bottomSheetCoordinator.ts +15 -15
- package/src/index.tsx +2 -4
- package/src/useBottomSheetManager.tsx +37 -48
- package/src/useBottomSheetState.ts +5 -17
- package/src/useScaleAnimation.ts +114 -0
- package/lib/commonjs/ScaleBackgroundWrapper.js +0 -69
- package/lib/commonjs/ScaleBackgroundWrapper.js.map +0 -1
- package/lib/typescript/src/ScaleBackgroundWrapper.d.ts +0 -32
- package/lib/typescript/src/ScaleBackgroundWrapper.d.ts.map +0 -1
- package/src/ScaleBackgroundWrapper.tsx +0 -98
package/src/bottomSheet.store.ts
CHANGED
|
@@ -16,7 +16,8 @@ export interface BottomSheetState {
|
|
|
16
16
|
type TriggerState = Omit<BottomSheetState, 'status'>;
|
|
17
17
|
|
|
18
18
|
interface BottomSheetStoreState {
|
|
19
|
-
|
|
19
|
+
sheetsById: Record<string, BottomSheetState>;
|
|
20
|
+
stackOrder: string[];
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
interface BottomSheetStoreActions {
|
|
@@ -29,102 +30,136 @@ interface BottomSheetStoreActions {
|
|
|
29
30
|
clearAll(): void;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
export type BottomSheetStore = BottomSheetStoreState & BottomSheetStoreActions;
|
|
34
|
+
|
|
32
35
|
export const useBottomSheetStore = create(
|
|
33
|
-
subscribeWithSelector<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
subscribeWithSelector<BottomSheetStore>((set) => ({
|
|
37
|
+
sheetsById: {},
|
|
38
|
+
stackOrder: [],
|
|
39
|
+
|
|
40
|
+
push: (sheet) =>
|
|
41
|
+
set((state) => {
|
|
42
|
+
if (state.sheetsById[sheet.id]) {
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
sheetsById: {
|
|
47
|
+
...state.sheetsById,
|
|
48
|
+
[sheet.id]: { ...sheet, status: 'opening' },
|
|
49
|
+
},
|
|
50
|
+
stackOrder: [...state.stackOrder, sheet.id],
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
|
|
54
|
+
switch: (sheet) =>
|
|
55
|
+
set((state) => {
|
|
56
|
+
if (state.sheetsById[sheet.id]) {
|
|
57
|
+
return state;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const newSheetsById = { ...state.sheetsById };
|
|
61
|
+
const topId = state.stackOrder[state.stackOrder.length - 1];
|
|
62
|
+
|
|
63
|
+
if (topId && newSheetsById[topId]) {
|
|
64
|
+
newSheetsById[topId] = {
|
|
65
|
+
...newSheetsById[topId],
|
|
66
|
+
status: 'hidden',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
newSheetsById[sheet.id] = { ...sheet, status: 'opening' };
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
sheetsById: newSheetsById,
|
|
74
|
+
stackOrder: [...state.stackOrder, sheet.id],
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
|
|
78
|
+
replace: (sheet) =>
|
|
79
|
+
set((state) => {
|
|
80
|
+
if (state.sheetsById[sheet.id]) {
|
|
81
|
+
return state;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const newSheetsById = { ...state.sheetsById };
|
|
85
|
+
const topId = state.stackOrder[state.stackOrder.length - 1];
|
|
86
|
+
|
|
87
|
+
if (topId && newSheetsById[topId]) {
|
|
88
|
+
newSheetsById[topId] = {
|
|
89
|
+
...newSheetsById[topId],
|
|
90
|
+
status: 'closing',
|
|
44
91
|
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const topIndex = stack.length - 1;
|
|
120
|
-
if (topIndex >= 0 && stack[topIndex]?.status === 'hidden') {
|
|
121
|
-
stack[topIndex] = { ...stack[topIndex], status: 'opening' };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return { stack };
|
|
125
|
-
}),
|
|
126
|
-
|
|
127
|
-
clearAll: () => set(() => ({ stack: [] })),
|
|
128
|
-
})
|
|
129
|
-
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
newSheetsById[sheet.id] = { ...sheet, status: 'opening' };
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
sheetsById: newSheetsById,
|
|
98
|
+
stackOrder: [...state.stackOrder, sheet.id],
|
|
99
|
+
};
|
|
100
|
+
}),
|
|
101
|
+
|
|
102
|
+
markOpen: (id) =>
|
|
103
|
+
set((state) => {
|
|
104
|
+
const sheet = state.sheetsById[id];
|
|
105
|
+
if (!sheet) {
|
|
106
|
+
return state;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
sheetsById: {
|
|
110
|
+
...state.sheetsById,
|
|
111
|
+
[id]: { ...sheet, status: 'open' },
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
|
|
116
|
+
startClosing: (id) =>
|
|
117
|
+
set((state) => {
|
|
118
|
+
const sheet = state.sheetsById[id];
|
|
119
|
+
if (!sheet || sheet.status === 'hidden') {
|
|
120
|
+
return state;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const newSheetsById = { ...state.sheetsById };
|
|
124
|
+
newSheetsById[id] = { ...sheet, status: 'closing' };
|
|
125
|
+
|
|
126
|
+
const index = state.stackOrder.indexOf(id);
|
|
127
|
+
const belowId = state.stackOrder[index - 1];
|
|
128
|
+
const belowSheet = belowId ? newSheetsById[belowId] : undefined;
|
|
129
|
+
|
|
130
|
+
if (belowId && belowSheet && belowSheet.status === 'hidden') {
|
|
131
|
+
newSheetsById[belowId] = { ...belowSheet, status: 'opening' };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { sheetsById: newSheetsById };
|
|
135
|
+
}),
|
|
136
|
+
|
|
137
|
+
finishClosing: (id) =>
|
|
138
|
+
set((state) => {
|
|
139
|
+
if (!state.sheetsById[id]) {
|
|
140
|
+
return state;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const newSheetsById = { ...state.sheetsById };
|
|
144
|
+
delete newSheetsById[id];
|
|
145
|
+
|
|
146
|
+
const newStackOrder = state.stackOrder.filter(
|
|
147
|
+
(sheetId) => sheetId !== id
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const topId = newStackOrder[newStackOrder.length - 1];
|
|
151
|
+
const topSheet = topId ? newSheetsById[topId] : undefined;
|
|
152
|
+
|
|
153
|
+
if (topId && topSheet && topSheet.status === 'hidden') {
|
|
154
|
+
newSheetsById[topId] = { ...topSheet, status: 'opening' };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
sheetsById: newSheetsById,
|
|
159
|
+
stackOrder: newStackOrder,
|
|
160
|
+
};
|
|
161
|
+
}),
|
|
162
|
+
|
|
163
|
+
clearAll: () => set(() => ({ sheetsById: {}, stackOrder: [] })),
|
|
164
|
+
}))
|
|
130
165
|
);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useBottomSheetStore } from './bottomSheet.store';
|
|
2
2
|
import { sheetRefs } from './refsMap';
|
|
3
3
|
|
|
4
|
-
export function initBottomSheetCoordinator() {
|
|
5
|
-
useBottomSheetStore.subscribe(
|
|
6
|
-
(s) =>
|
|
4
|
+
export function initBottomSheetCoordinator(groupId: string) {
|
|
5
|
+
return useBottomSheetStore.subscribe(
|
|
6
|
+
(s) =>
|
|
7
|
+
s.stackOrder
|
|
8
|
+
.filter((id) => s.sheetsById[id]?.groupId === groupId)
|
|
9
|
+
.map((id) => ({ id, status: s.sheetsById[id]?.status })),
|
|
7
10
|
(next, prev) => {
|
|
8
11
|
next.forEach(({ id, status }) => {
|
|
9
12
|
const prevStatus = prev.find((p) => p.id === id)?.status;
|
|
@@ -13,19 +16,18 @@ export function initBottomSheetCoordinator() {
|
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const ref = sheetRefs[id]?.current;
|
|
16
|
-
if (!ref) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
19
|
|
|
20
20
|
switch (status) {
|
|
21
21
|
case 'opening':
|
|
22
|
-
|
|
22
|
+
requestAnimationFrame(() => {
|
|
23
|
+
sheetRefs[id]?.current?.expand();
|
|
24
|
+
});
|
|
23
25
|
break;
|
|
24
26
|
case 'hidden':
|
|
25
|
-
ref.close();
|
|
27
|
+
if (ref) ref.close();
|
|
26
28
|
break;
|
|
27
29
|
case 'closing':
|
|
28
|
-
ref.close();
|
|
30
|
+
if (ref) ref.close();
|
|
29
31
|
break;
|
|
30
32
|
}
|
|
31
33
|
});
|
|
@@ -42,9 +44,8 @@ export function createSheetEventHandlers(sheetId: string) {
|
|
|
42
44
|
useBottomSheetStore.getState();
|
|
43
45
|
|
|
44
46
|
const handleAnimate = (fromIndex: number, toIndex: number) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
.stack.find((s) => s.id === sheetId)?.status;
|
|
47
|
+
const state = useBottomSheetStore.getState();
|
|
48
|
+
const currentStatus = state.sheetsById[sheetId]?.status;
|
|
48
49
|
|
|
49
50
|
// Sheet is closing (animating to -1)
|
|
50
51
|
if (toIndex === -1) {
|
|
@@ -60,9 +61,8 @@ export function createSheetEventHandlers(sheetId: string) {
|
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
const handleClose = () => {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
.stack.find((s) => s.id === sheetId)?.status;
|
|
64
|
+
const state = useBottomSheetStore.getState();
|
|
65
|
+
const currentStatus = state.sheetsById[sheetId]?.status;
|
|
66
66
|
|
|
67
67
|
if (currentStatus !== 'hidden') {
|
|
68
68
|
finishClosing(sheetId);
|
package/src/index.tsx
CHANGED
|
@@ -3,7 +3,5 @@ export { BottomSheetManagerProvider } from './BottomSheetManager.provider';
|
|
|
3
3
|
export { useBottomSheetManager } from './useBottomSheetManager';
|
|
4
4
|
export { useBottomSheetState } from './useBottomSheetState';
|
|
5
5
|
export { BottomSheetManaged } from './BottomSheetManaged';
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
type ScaleBackgroundConfig,
|
|
9
|
-
} from './ScaleBackgroundWrapper';
|
|
6
|
+
export { BottomSheetScaleView } from './BottomSheetScaleView';
|
|
7
|
+
export { type ScaleConfig } from './useScaleAnimation';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { useBottomSheetStore, type OpenMode } from './bottomSheet.store';
|
|
4
4
|
import { useMaybeBottomSheetManagerContext } from './BottomSheetManager.provider';
|
|
@@ -26,62 +26,51 @@ export const useBottomSheetManager = () => {
|
|
|
26
26
|
shallow
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
const openBottomSheet =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
options.groupId || bottomSheetManagerContext?.groupId || 'default';
|
|
29
|
+
const openBottomSheet = (
|
|
30
|
+
content: React.ReactElement,
|
|
31
|
+
options: {
|
|
32
|
+
id?: string;
|
|
33
|
+
groupId?: string;
|
|
34
|
+
mode?: OpenMode;
|
|
35
|
+
scaleBackground?: boolean;
|
|
36
|
+
} = {}
|
|
37
|
+
) => {
|
|
38
|
+
const groupId =
|
|
39
|
+
options.groupId || bottomSheetManagerContext?.groupId || 'default';
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const id = options.id || Math.random().toString(36);
|
|
42
|
+
const ref = React.createRef<BottomSheetMethods>();
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
sheetRefs[id] = ref;
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const contentWithRef = React.cloneElement(content, { ref });
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const sheetData = {
|
|
50
|
+
id,
|
|
51
|
+
groupId,
|
|
52
|
+
content: contentWithRef,
|
|
53
|
+
scaleBackground: options.scaleBackground,
|
|
54
|
+
};
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
if (options.mode === 'replace') {
|
|
57
|
+
replaceBottomSheet(sheetData);
|
|
58
|
+
} else if (options.mode === 'switch') {
|
|
59
|
+
switchBottomSheet(sheetData);
|
|
60
|
+
} else {
|
|
61
|
+
pushBottomSheet(sheetData);
|
|
62
|
+
}
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
[
|
|
68
|
-
bottomSheetManagerContext?.groupId,
|
|
69
|
-
pushBottomSheet,
|
|
70
|
-
replaceBottomSheet,
|
|
71
|
-
switchBottomSheet,
|
|
72
|
-
]
|
|
73
|
-
);
|
|
64
|
+
return id;
|
|
65
|
+
};
|
|
74
66
|
|
|
75
|
-
const close =
|
|
76
|
-
(id
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
[startClosing]
|
|
80
|
-
);
|
|
67
|
+
const close = (id: string) => {
|
|
68
|
+
startClosing(id);
|
|
69
|
+
};
|
|
81
70
|
|
|
82
|
-
const clearAll =
|
|
71
|
+
const clearAll = () => {
|
|
83
72
|
storeClearAll();
|
|
84
|
-
}
|
|
73
|
+
};
|
|
85
74
|
|
|
86
75
|
return {
|
|
87
76
|
clearAll,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
2
1
|
import { useMaybeBottomSheetContext } from './BottomSheet.context';
|
|
3
2
|
import {
|
|
4
3
|
useBottomSheetStore,
|
|
5
4
|
type BottomSheetState,
|
|
6
5
|
} from './bottomSheet.store';
|
|
7
|
-
import { shallow } from 'zustand/shallow';
|
|
8
6
|
|
|
9
7
|
export function useBottomSheetState(): {
|
|
10
8
|
bottomSheetState: BottomSheetState;
|
|
@@ -12,30 +10,20 @@ export function useBottomSheetState(): {
|
|
|
12
10
|
closeBottomSheet: () => void;
|
|
13
11
|
} {
|
|
14
12
|
const context = useMaybeBottomSheetContext();
|
|
15
|
-
const { bottomSheetsStack, startClosing } = useBottomSheetStore(
|
|
16
|
-
(store) => ({
|
|
17
|
-
bottomSheetsStack: store.stack,
|
|
18
|
-
startClosing: store.startClosing,
|
|
19
|
-
}),
|
|
20
|
-
shallow
|
|
21
|
-
);
|
|
22
13
|
|
|
23
|
-
const bottomSheetState =
|
|
24
|
-
() =>
|
|
25
|
-
bottomSheetsStack.find((bottomSheet) => bottomSheet.id === context?.id),
|
|
26
|
-
[bottomSheetsStack, context?.id]
|
|
14
|
+
const bottomSheetState = useBottomSheetStore(
|
|
15
|
+
(state) => state.sheetsById[context?.id!]
|
|
27
16
|
);
|
|
28
17
|
|
|
18
|
+
const startClosing = useBottomSheetStore((state) => state.startClosing);
|
|
19
|
+
|
|
29
20
|
if (!bottomSheetState) {
|
|
30
21
|
throw new Error(
|
|
31
22
|
'useBottomSheetState must be used within a BottomSheetProvider'
|
|
32
23
|
);
|
|
33
24
|
}
|
|
34
25
|
|
|
35
|
-
const close =
|
|
36
|
-
() => startClosing(bottomSheetState.id),
|
|
37
|
-
[bottomSheetState.id, startClosing]
|
|
38
|
-
);
|
|
26
|
+
const close = () => startClosing(bottomSheetState.id);
|
|
39
27
|
|
|
40
28
|
return {
|
|
41
29
|
bottomSheetState,
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useAnimatedStyle,
|
|
4
|
+
useDerivedValue,
|
|
5
|
+
withTiming,
|
|
6
|
+
} from 'react-native-reanimated';
|
|
7
|
+
import {
|
|
8
|
+
useBottomSheetStore,
|
|
9
|
+
type BottomSheetStore,
|
|
10
|
+
} from './bottomSheet.store';
|
|
11
|
+
|
|
12
|
+
export interface ScaleConfig {
|
|
13
|
+
/** Scale factor when sheet is open (default: 0.92) */
|
|
14
|
+
scale?: number;
|
|
15
|
+
/** Vertical translation when sheet is open (default: 10) */
|
|
16
|
+
translateY?: number;
|
|
17
|
+
/** Border radius when sheet is open (default: 12) */
|
|
18
|
+
borderRadius?: number;
|
|
19
|
+
/** Animation duration in ms (default: 300) */
|
|
20
|
+
duration?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_CONFIG: Required<ScaleConfig> = {
|
|
24
|
+
scale: 0.92,
|
|
25
|
+
translateY: 10,
|
|
26
|
+
borderRadius: 12,
|
|
27
|
+
duration: 300,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the number of sheets with scaleBackground above a given element.
|
|
32
|
+
* For background wrapper, pass undefined as sheetId - returns 0 or 1 (binary).
|
|
33
|
+
* For sheets, returns the count of scaleBackground sheets above it.
|
|
34
|
+
* Uses shallow comparison internally for optimal re-renders.
|
|
35
|
+
*/
|
|
36
|
+
export function useScaleDepth(groupId: string, sheetId?: string): number {
|
|
37
|
+
const prevDepthRef = useRef(0);
|
|
38
|
+
|
|
39
|
+
const scaleDepthSelector = (state: BottomSheetStore) => {
|
|
40
|
+
const { stackOrder, sheetsById } = state;
|
|
41
|
+
|
|
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
|
+
const startIndex = sheetId ? stackOrder.indexOf(sheetId) + 1 : 0;
|
|
45
|
+
|
|
46
|
+
if (sheetId && startIndex === 0) {
|
|
47
|
+
// Sheet not found in stack, return previous value to avoid flicker
|
|
48
|
+
return prevDepthRef.current;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let depth = 0;
|
|
52
|
+
for (let i = startIndex; i < stackOrder.length; i++) {
|
|
53
|
+
const id = stackOrder[i]!;
|
|
54
|
+
const sheet = sheetsById[id];
|
|
55
|
+
if (
|
|
56
|
+
sheet &&
|
|
57
|
+
sheet.groupId === groupId &&
|
|
58
|
+
sheet.scaleBackground &&
|
|
59
|
+
sheet.status !== 'closing'
|
|
60
|
+
) {
|
|
61
|
+
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
|
+
if (!sheetId) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
prevDepthRef.current = depth;
|
|
71
|
+
return depth;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return useBottomSheetStore(scaleDepthSelector);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns animated style for scale effect based on depth.
|
|
79
|
+
* Uses power scaling: scale^depth for cascading effect.
|
|
80
|
+
*/
|
|
81
|
+
export function useScaleAnimatedStyle(depth: number, config?: ScaleConfig) {
|
|
82
|
+
const {
|
|
83
|
+
scale = DEFAULT_CONFIG.scale,
|
|
84
|
+
translateY = DEFAULT_CONFIG.translateY,
|
|
85
|
+
borderRadius = DEFAULT_CONFIG.borderRadius,
|
|
86
|
+
duration = DEFAULT_CONFIG.duration,
|
|
87
|
+
} = config ?? {};
|
|
88
|
+
|
|
89
|
+
const progress = useDerivedValue(() => {
|
|
90
|
+
return withTiming(depth, { duration });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return useAnimatedStyle(() => {
|
|
94
|
+
const p = progress.value;
|
|
95
|
+
|
|
96
|
+
if (p === 0) {
|
|
97
|
+
return {
|
|
98
|
+
transform: [{ scale: 1 }, { translateY: 0 }],
|
|
99
|
+
borderRadius: 0,
|
|
100
|
+
overflow: 'visible',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const currentScale = Math.pow(scale, p);
|
|
105
|
+
const currentTranslateY = translateY * p;
|
|
106
|
+
const currentBorderRadius = Math.min(borderRadius * p, borderRadius);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
transform: [{ scale: currentScale }, { translateY: currentTranslateY }],
|
|
110
|
+
borderRadius: currentBorderRadius,
|
|
111
|
+
overflow: 'hidden',
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ScaleBackgroundWrapper = ScaleBackgroundWrapper;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _reactNative = require("react-native");
|
|
9
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
-
var _shallow = require("zustand/shallow");
|
|
11
|
-
var _BottomSheetManager = require("./BottomSheetManager.context");
|
|
12
|
-
var _bottomSheet = require("./bottomSheet.store");
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
-
/**
|
|
17
|
-
* Wraps content with iOS-style scale animation when a bottom sheet with
|
|
18
|
-
* scaleBackground: true is open. Place your main content inside this wrapper,
|
|
19
|
-
* but keep BottomSheetHost outside of it.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* <BottomSheetManagerProvider id="default">
|
|
24
|
-
* <ScaleBackgroundWrapper config={{ scale: 0.92 }}>
|
|
25
|
-
* <MainContent />
|
|
26
|
-
* </ScaleBackgroundWrapper>
|
|
27
|
-
* <BottomSheetHost />
|
|
28
|
-
* </BottomSheetManagerProvider>
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
function ScaleBackgroundWrapper({
|
|
32
|
-
children,
|
|
33
|
-
config
|
|
34
|
-
}) {
|
|
35
|
-
const context = (0, _react.useContext)(_BottomSheetManager.BottomSheetManagerContext);
|
|
36
|
-
const groupId = context?.groupId ?? 'default';
|
|
37
|
-
const {
|
|
38
|
-
scale = 0.92,
|
|
39
|
-
translateY = 10,
|
|
40
|
-
borderRadius = 12,
|
|
41
|
-
duration = 300
|
|
42
|
-
} = config ?? {};
|
|
43
|
-
const hasActiveScaleSheet = (0, _bottomSheet.useBottomSheetStore)(store => store.stack.some(sheet => sheet.groupId === groupId && sheet.scaleBackground && sheet.status !== 'closing'), _shallow.shallow);
|
|
44
|
-
const animationProgress = (0, _reactNativeReanimated.useDerivedValue)(() => (0, _reactNativeReanimated.withTiming)(hasActiveScaleSheet ? 1 : 0, {
|
|
45
|
-
duration
|
|
46
|
-
}));
|
|
47
|
-
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
48
|
-
const progress = animationProgress.value;
|
|
49
|
-
return {
|
|
50
|
-
transform: [{
|
|
51
|
-
scale: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [1, scale])
|
|
52
|
-
}, {
|
|
53
|
-
translateY: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [0, translateY])
|
|
54
|
-
}],
|
|
55
|
-
borderRadius: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [0, borderRadius]),
|
|
56
|
-
overflow: progress > 0 ? 'hidden' : 'visible'
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
60
|
-
style: [styles.scaleWrapper, animatedStyle],
|
|
61
|
-
children: children
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
const styles = _reactNative.StyleSheet.create({
|
|
65
|
-
scaleWrapper: {
|
|
66
|
-
flex: 1
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
//# sourceMappingURL=ScaleBackgroundWrapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_reactNativeReanimated","_interopRequireWildcard","_shallow","_BottomSheetManager","_bottomSheet","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","ScaleBackgroundWrapper","children","config","context","useContext","BottomSheetManagerContext","groupId","scale","translateY","borderRadius","duration","hasActiveScaleSheet","useBottomSheetStore","store","stack","some","sheet","scaleBackground","status","shallow","animationProgress","useDerivedValue","withTiming","animatedStyle","useAnimatedStyle","progress","value","transform","interpolate","overflow","jsx","View","style","styles","scaleWrapper","StyleSheet","create","flex"],"sourceRoot":"../../src","sources":["ScaleBackgroundWrapper.tsx"],"mappings":"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","ignoreList":[]}
|