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.
Files changed (70) hide show
  1. package/lib/commonjs/BottomSheet.context.js.map +1 -1
  2. package/lib/commonjs/BottomSheetBackdrop.js +76 -0
  3. package/lib/commonjs/BottomSheetBackdrop.js.map +1 -0
  4. package/lib/commonjs/BottomSheetHost.js +215 -51
  5. package/lib/commonjs/BottomSheetHost.js.map +1 -1
  6. package/lib/commonjs/BottomSheetManaged.js +128 -38
  7. package/lib/commonjs/BottomSheetManaged.js.map +1 -1
  8. package/lib/commonjs/BottomSheetManager.context.js.map +1 -1
  9. package/lib/commonjs/BottomSheetManager.provider.js +38 -13
  10. package/lib/commonjs/BottomSheetManager.provider.js.map +1 -1
  11. package/lib/commonjs/BottomSheetScaleView.js +67 -0
  12. package/lib/commonjs/BottomSheetScaleView.js.map +1 -0
  13. package/lib/commonjs/animatedRegistry.js +25 -0
  14. package/lib/commonjs/animatedRegistry.js.map +1 -0
  15. package/lib/commonjs/bottomSheet.store.js +86 -73
  16. package/lib/commonjs/bottomSheet.store.js.map +1 -1
  17. package/lib/commonjs/bottomSheetCoordinator.js +12 -14
  18. package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
  19. package/lib/commonjs/index.js +3 -3
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/useBottomSheetManager.js +88 -44
  22. package/lib/commonjs/useBottomSheetManager.js.map +1 -1
  23. package/lib/commonjs/useBottomSheetState.js +40 -17
  24. package/lib/commonjs/useBottomSheetState.js.map +1 -1
  25. package/lib/commonjs/useScaleAnimation.js +108 -0
  26. package/lib/commonjs/useScaleAnimation.js.map +1 -0
  27. package/lib/typescript/example/src/App.d.ts +0 -2
  28. package/lib/typescript/example/src/App.d.ts.map +1 -1
  29. package/lib/typescript/src/BottomSheetBackdrop.d.ts +12 -0
  30. package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -0
  31. package/lib/typescript/src/BottomSheetHost.d.ts +2 -6
  32. package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
  33. package/lib/typescript/src/BottomSheetManaged.d.ts.map +1 -1
  34. package/lib/typescript/src/BottomSheetManager.context.d.ts +2 -0
  35. package/lib/typescript/src/BottomSheetManager.context.d.ts.map +1 -1
  36. package/lib/typescript/src/BottomSheetManager.provider.d.ts +4 -3
  37. package/lib/typescript/src/BottomSheetManager.provider.d.ts.map +1 -1
  38. package/lib/typescript/src/BottomSheetScaleView.d.ts +18 -0
  39. package/lib/typescript/src/BottomSheetScaleView.d.ts.map +1 -0
  40. package/lib/typescript/src/animatedRegistry.d.ts +4 -0
  41. package/lib/typescript/src/animatedRegistry.d.ts.map +1 -0
  42. package/lib/typescript/src/bottomSheet.store.d.ts +6 -4
  43. package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
  44. package/lib/typescript/src/bottomSheetCoordinator.d.ts +1 -1
  45. package/lib/typescript/src/bottomSheetCoordinator.d.ts.map +1 -1
  46. package/lib/typescript/src/index.d.ts +2 -1
  47. package/lib/typescript/src/index.d.ts.map +1 -1
  48. package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
  49. package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
  50. package/lib/typescript/src/useScaleAnimation.d.ts +43 -0
  51. package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -0
  52. package/package.json +9 -2
  53. package/src/BottomSheetBackdrop.tsx +61 -0
  54. package/src/BottomSheetHost.tsx +89 -51
  55. package/src/BottomSheetManaged.tsx +26 -33
  56. package/src/BottomSheetManager.context.tsx +2 -0
  57. package/src/BottomSheetManager.provider.tsx +10 -6
  58. package/src/BottomSheetScaleView.tsx +41 -0
  59. package/src/animatedRegistry.ts +22 -0
  60. package/src/bottomSheet.store.ts +132 -97
  61. package/src/bottomSheetCoordinator.ts +15 -15
  62. package/src/index.tsx +2 -4
  63. package/src/useBottomSheetManager.tsx +37 -48
  64. package/src/useBottomSheetState.ts +5 -17
  65. package/src/useScaleAnimation.ts +114 -0
  66. package/lib/commonjs/ScaleBackgroundWrapper.js +0 -69
  67. package/lib/commonjs/ScaleBackgroundWrapper.js.map +0 -1
  68. package/lib/typescript/src/ScaleBackgroundWrapper.d.ts +0 -32
  69. package/lib/typescript/src/ScaleBackgroundWrapper.d.ts.map +0 -1
  70. package/src/ScaleBackgroundWrapper.tsx +0 -98
@@ -16,7 +16,8 @@ export interface BottomSheetState {
16
16
  type TriggerState = Omit<BottomSheetState, 'status'>;
17
17
 
18
18
  interface BottomSheetStoreState {
19
- stack: BottomSheetState[];
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<BottomSheetStoreState & BottomSheetStoreActions>(
34
- (set) => ({
35
- stack: [],
36
-
37
- push: (sheet) =>
38
- set((state) => {
39
- if (state.stack.some((s) => s.id === sheet.id)) {
40
- return { stack: state.stack };
41
- }
42
- return {
43
- stack: [...state.stack, { ...sheet, status: 'opening' }],
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
- switch: (sheet) =>
47
- set((state) => {
48
- if (state.stack.some((s) => s.id === sheet.id)) {
49
- return { stack: state.stack };
50
- }
51
-
52
- const stack = [...state.stack];
53
-
54
- if (stack.length) {
55
- const topIndex = stack.length - 1;
56
- if (stack[topIndex]) {
57
- stack[topIndex] = { ...stack[topIndex], status: 'hidden' };
58
- }
59
- }
60
-
61
- stack.push({ ...sheet, status: 'opening' });
62
-
63
- return { stack };
64
- }),
65
-
66
- replace: (sheet) =>
67
- set((state) => {
68
- if (state.stack.some((s) => s.id === sheet.id)) {
69
- return { stack: state.stack };
70
- }
71
-
72
- const stack = [...state.stack];
73
- const prevTop = stack.pop();
74
-
75
- if (prevTop) {
76
- stack.push({ ...prevTop, status: 'closing' });
77
- }
78
- stack.push({ ...sheet, status: 'opening' });
79
-
80
- return { stack };
81
- }),
82
- markOpen: (id) =>
83
- set((state) => {
84
- const stack = state.stack.map((s) =>
85
- s.id === id ? { ...s, status: 'open' as BottomSheetStatus } : s
86
- );
87
- return { stack };
88
- }),
89
-
90
- startClosing: (id) =>
91
- set((state) => {
92
- const stack = [...state.stack];
93
- const index = stack.findIndex((s) => s.id === id);
94
- if (index === -1) {
95
- return { stack };
96
- }
97
-
98
- const closing = stack[index];
99
- if (closing?.status === 'hidden') {
100
- return { stack };
101
- }
102
-
103
- if (closing) {
104
- stack[index] = { ...closing, status: 'closing' };
105
- }
106
-
107
- const below = stack[index - 1];
108
- if (below && below.status === 'hidden') {
109
- stack[index - 1] = { ...below, status: 'opening' };
110
- }
111
-
112
- return { stack };
113
- }),
114
-
115
- finishClosing: (id) =>
116
- set((state) => {
117
- const stack = state.stack.filter((s) => s.id !== id);
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) => s.stack.map(({ id, status }) => ({ id, status })),
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
- ref.expand();
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 currentStatus = useBottomSheetStore
46
- .getState()
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 currentStatus = useBottomSheetStore
64
- .getState()
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
- ScaleBackgroundWrapper,
8
- type ScaleBackgroundConfig,
9
- } from './ScaleBackgroundWrapper';
6
+ export { BottomSheetScaleView } from './BottomSheetScaleView';
7
+ export { type ScaleConfig } from './useScaleAnimation';
@@ -1,4 +1,4 @@
1
- import React, { useCallback } from '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 = useCallback(
30
- (
31
- content: React.ReactElement,
32
- options: {
33
- id?: string;
34
- groupId?: string;
35
- mode?: OpenMode;
36
- scaleBackground?: boolean;
37
- } = {}
38
- ) => {
39
- const groupId =
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
- const id = options.id || Math.random().toString(36);
43
- const ref = React.createRef<BottomSheetMethods>();
41
+ const id = options.id || Math.random().toString(36);
42
+ const ref = React.createRef<BottomSheetMethods>();
44
43
 
45
- sheetRefs[id] = ref;
44
+ sheetRefs[id] = ref;
46
45
 
47
- // @ts-ignore
48
- const contentWithRef = React.cloneElement(content, { ref });
46
+ // @ts-ignore
47
+ const contentWithRef = React.cloneElement(content, { ref });
49
48
 
50
- const sheetData = {
51
- id,
52
- groupId,
53
- content: contentWithRef,
54
- scaleBackground: options.scaleBackground,
55
- };
49
+ const sheetData = {
50
+ id,
51
+ groupId,
52
+ content: contentWithRef,
53
+ scaleBackground: options.scaleBackground,
54
+ };
56
55
 
57
- if (options.mode === 'replace') {
58
- replaceBottomSheet(sheetData);
59
- } else if (options.mode === 'switch') {
60
- switchBottomSheet(sheetData);
61
- } else {
62
- pushBottomSheet(sheetData);
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
- return id;
66
- },
67
- [
68
- bottomSheetManagerContext?.groupId,
69
- pushBottomSheet,
70
- replaceBottomSheet,
71
- switchBottomSheet,
72
- ]
73
- );
64
+ return id;
65
+ };
74
66
 
75
- const close = useCallback(
76
- (id: string) => {
77
- startClosing(id);
78
- },
79
- [startClosing]
80
- );
67
+ const close = (id: string) => {
68
+ startClosing(id);
69
+ };
81
70
 
82
- const clearAll = useCallback(() => {
71
+ const clearAll = () => {
83
72
  storeClearAll();
84
- }, [storeClearAll]);
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 = useMemo(
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 = useCallback(
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":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,uBAAA,CAAAH,OAAA;AAMA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAA0D,IAAAO,WAAA,GAAAP,OAAA;AAAA,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAA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