@umituz/react-native-bottom-sheet 1.3.2 → 1.3.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-bottom-sheet",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Modern, performant bottom sheets for React Native with preset configurations, keyboard handling, and smooth animations",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* BottomSheetModal Component
|
|
3
|
-
*
|
|
4
|
-
* Modal version of bottom sheet using @gorhom/bottom-sheet.
|
|
5
|
-
* Provides a clean, theme-aware API for modal bottom sheets.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Modal presentation (overlays entire screen)
|
|
9
|
-
* - Snap point support (percentage, fixed, dynamic)
|
|
10
|
-
* - Backdrop with tap-to-close
|
|
11
|
-
* - Keyboard handling (interactive, fillParent, extend)
|
|
12
|
-
* - Theme-aware colors
|
|
13
|
-
* - Handle indicator
|
|
14
|
-
* - Pan down to close
|
|
15
|
-
* - Smooth animations with Reanimated v3
|
|
16
|
-
*
|
|
17
|
-
* Usage:
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const { modalRef, present, dismiss } = useBottomSheetModal();
|
|
20
|
-
*
|
|
21
|
-
* <BottomSheetModal
|
|
22
|
-
* ref={modalRef}
|
|
23
|
-
* preset="medium"
|
|
24
|
-
* onDismiss={() => console.log('Dismissed')}
|
|
25
|
-
* >
|
|
26
|
-
* <View>
|
|
27
|
-
* <Text>Modal Content</Text>
|
|
28
|
-
* </View>
|
|
29
|
-
* </BottomSheetModal>
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import React, { forwardRef, useCallback, useMemo } from 'react';
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo, useImperativeHandle, useRef } from 'react';
|
|
34
2
|
import { StyleSheet } from 'react-native';
|
|
35
3
|
import {
|
|
36
4
|
BottomSheetModal as GorhomBottomSheetModal,
|
|
@@ -47,9 +15,6 @@ import type {
|
|
|
47
15
|
} from '../../domain/entities/BottomSheet';
|
|
48
16
|
import { BottomSheetUtils } from '../../domain/entities/BottomSheet';
|
|
49
17
|
|
|
50
|
-
/**
|
|
51
|
-
* Bottom sheet modal ref methods
|
|
52
|
-
*/
|
|
53
18
|
export interface BottomSheetModalRef {
|
|
54
19
|
present: () => void;
|
|
55
20
|
dismiss: () => void;
|
|
@@ -59,215 +24,113 @@ export interface BottomSheetModalRef {
|
|
|
59
24
|
collapse: () => void;
|
|
60
25
|
}
|
|
61
26
|
|
|
62
|
-
/**
|
|
63
|
-
* Bottom sheet modal component props
|
|
64
|
-
*/
|
|
65
27
|
export interface BottomSheetModalProps {
|
|
66
|
-
/**
|
|
67
|
-
* Bottom sheet content
|
|
68
|
-
*/
|
|
69
28
|
children: React.ReactNode;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Preset configuration (small, medium, large, full)
|
|
73
|
-
*/
|
|
74
29
|
preset?: BottomSheetPreset;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Custom snap points (overrides preset)
|
|
78
|
-
*/
|
|
79
30
|
snapPoints?: SnapPoint[];
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Initial snap point index
|
|
83
|
-
*/
|
|
84
31
|
initialIndex?: number;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Enable backdrop
|
|
88
|
-
*/
|
|
89
32
|
enableBackdrop?: boolean;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Backdrop appears at this snap index
|
|
93
|
-
*/
|
|
94
33
|
backdropAppearsOnIndex?: number;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Backdrop disappears at this snap index
|
|
98
|
-
*/
|
|
99
34
|
backdropDisappearsOnIndex?: number;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Keyboard behavior strategy
|
|
103
|
-
*/
|
|
104
35
|
keyboardBehavior?: KeyboardBehavior;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Enable handle indicator
|
|
108
|
-
*/
|
|
109
36
|
enableHandleIndicator?: boolean;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Enable pan down to close
|
|
113
|
-
*/
|
|
114
37
|
enablePanDownToClose?: boolean;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Enable dynamic sizing
|
|
118
|
-
*/
|
|
119
38
|
enableDynamicSizing?: boolean;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Callback when sheet changes position
|
|
123
|
-
*/
|
|
124
39
|
onChange?: (index: number) => void;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Callback when sheet is dismissed
|
|
128
|
-
*/
|
|
129
40
|
onDismiss?: () => void;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Background color of the sheet
|
|
133
|
-
*/
|
|
134
41
|
backgroundColor?: string;
|
|
135
42
|
}
|
|
136
43
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
44
|
+
export const BottomSheetModal = forwardRef<BottomSheetModalRef, BottomSheetModalProps>((props, ref) => {
|
|
45
|
+
const {
|
|
46
|
+
children,
|
|
47
|
+
preset = 'medium',
|
|
48
|
+
snapPoints: customSnapPoints,
|
|
49
|
+
initialIndex,
|
|
50
|
+
enableBackdrop = true,
|
|
51
|
+
backdropAppearsOnIndex,
|
|
52
|
+
backdropDisappearsOnIndex,
|
|
53
|
+
keyboardBehavior = 'interactive',
|
|
54
|
+
enableHandleIndicator = true,
|
|
55
|
+
enablePanDownToClose = true,
|
|
56
|
+
enableDynamicSizing = false,
|
|
57
|
+
onChange,
|
|
58
|
+
onDismiss,
|
|
59
|
+
backgroundColor,
|
|
60
|
+
} = props;
|
|
61
|
+
|
|
62
|
+
const tokens = useAppDesignTokens();
|
|
63
|
+
const modalRef = useRef<GorhomBottomSheetModal>(null);
|
|
64
|
+
|
|
65
|
+
const config: BottomSheetConfig = useMemo(() => {
|
|
66
|
+
if (customSnapPoints) {
|
|
67
|
+
return BottomSheetUtils.createConfig({
|
|
68
|
+
snapPoints: customSnapPoints,
|
|
69
|
+
initialIndex,
|
|
70
|
+
enableBackdrop,
|
|
71
|
+
backdropAppearsOnIndex,
|
|
72
|
+
backdropDisappearsOnIndex,
|
|
73
|
+
keyboardBehavior,
|
|
74
|
+
enableHandleIndicator,
|
|
75
|
+
enablePanDownToClose,
|
|
76
|
+
enableDynamicSizing,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return BottomSheetUtils.getPreset(preset);
|
|
80
|
+
}, [preset, customSnapPoints, initialIndex, enableBackdrop, backdropAppearsOnIndex, backdropDisappearsOnIndex, keyboardBehavior, enableHandleIndicator, enablePanDownToClose, enableDynamicSizing]);
|
|
81
|
+
|
|
82
|
+
const renderBackdrop = useCallback(
|
|
83
|
+
(backdropProps: BottomSheetBackdropProps) =>
|
|
84
|
+
enableBackdrop ? (
|
|
85
|
+
<BottomSheetBackdrop
|
|
86
|
+
{...backdropProps}
|
|
87
|
+
appearsOnIndex={config.backdropAppearsOnIndex ?? 0}
|
|
88
|
+
disappearsOnIndex={config.backdropDisappearsOnIndex ?? -1}
|
|
89
|
+
opacity={0.5}
|
|
90
|
+
pressBehavior="close"
|
|
91
|
+
/>
|
|
92
|
+
) : null,
|
|
93
|
+
[enableBackdrop, config.backdropAppearsOnIndex, config.backdropDisappearsOnIndex]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const handleSheetChange = useCallback(
|
|
97
|
+
(index: number) => {
|
|
98
|
+
onChange?.(index);
|
|
99
|
+
if (index === -1) onDismiss?.();
|
|
160
100
|
},
|
|
161
|
-
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// Render backdrop component (must be before early return to maintain hook order)
|
|
196
|
-
const renderBackdrop = useCallback(
|
|
197
|
-
(props: BottomSheetBackdropProps) =>
|
|
198
|
-
enableBackdrop ? (
|
|
199
|
-
<BottomSheetBackdrop
|
|
200
|
-
{...props}
|
|
201
|
-
appearsOnIndex={config.backdropAppearsOnIndex ?? 0}
|
|
202
|
-
disappearsOnIndex={config.backdropDisappearsOnIndex ?? -1}
|
|
203
|
-
opacity={0.5}
|
|
204
|
-
pressBehavior="close"
|
|
205
|
-
/>
|
|
206
|
-
) : null,
|
|
207
|
-
[enableBackdrop, config.backdropAppearsOnIndex, config.backdropDisappearsOnIndex]
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
// Handle sheet changes (must be before early return to maintain hook order)
|
|
211
|
-
const handleSheetChange = useCallback(
|
|
212
|
-
(index: number) => {
|
|
213
|
-
onChange?.(index);
|
|
214
|
-
if (index === -1) {
|
|
215
|
-
onDismiss?.();
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
[onChange, onDismiss]
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
// Expose ref methods
|
|
222
|
-
React.useImperativeHandle(ref, () => ({
|
|
223
|
-
present: () => {
|
|
224
|
-
modalRef.current?.present();
|
|
225
|
-
},
|
|
226
|
-
dismiss: () => {
|
|
227
|
-
modalRef.current?.dismiss();
|
|
228
|
-
},
|
|
229
|
-
snapToIndex: (index: number) => {
|
|
230
|
-
modalRef.current?.snapToIndex(index);
|
|
231
|
-
},
|
|
232
|
-
snapToPosition: (position: string | number) => {
|
|
233
|
-
modalRef.current?.snapToPosition(position);
|
|
234
|
-
},
|
|
235
|
-
expand: () => {
|
|
236
|
-
modalRef.current?.expand();
|
|
237
|
-
},
|
|
238
|
-
collapse: () => {
|
|
239
|
-
modalRef.current?.collapse();
|
|
240
|
-
},
|
|
241
|
-
}), []);
|
|
242
|
-
|
|
243
|
-
return (
|
|
244
|
-
<GorhomBottomSheetModal
|
|
245
|
-
ref={modalRef}
|
|
246
|
-
index={-1}
|
|
247
|
-
snapPoints={config.snapPoints}
|
|
248
|
-
enableDynamicSizing={config.enableDynamicSizing}
|
|
249
|
-
backdropComponent={renderBackdrop}
|
|
250
|
-
keyboardBehavior={config.keyboardBehavior}
|
|
251
|
-
enableHandlePanningGesture={config.enableHandleIndicator}
|
|
252
|
-
enablePanDownToClose={config.enablePanDownToClose}
|
|
253
|
-
onChange={handleSheetChange}
|
|
254
|
-
onDismiss={onDismiss}
|
|
255
|
-
backgroundStyle={[
|
|
256
|
-
styles.background,
|
|
257
|
-
{ backgroundColor: backgroundColor || tokens.colors.surface },
|
|
258
|
-
]}
|
|
259
|
-
handleIndicatorStyle={[
|
|
260
|
-
styles.handleIndicator,
|
|
261
|
-
{ backgroundColor: tokens.colors.border },
|
|
262
|
-
]}
|
|
263
|
-
>
|
|
264
|
-
<BottomSheetView style={styles.contentContainer}>
|
|
265
|
-
{children}
|
|
266
|
-
</BottomSheetView>
|
|
267
|
-
</GorhomBottomSheetModal>
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
);
|
|
101
|
+
[onChange, onDismiss]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
useImperativeHandle(ref, () => ({
|
|
105
|
+
present: () => modalRef.current?.present(),
|
|
106
|
+
dismiss: () => modalRef.current?.dismiss(),
|
|
107
|
+
snapToIndex: (index: number) => modalRef.current?.snapToIndex(index),
|
|
108
|
+
snapToPosition: (pos: string | number) => modalRef.current?.snapToPosition(pos),
|
|
109
|
+
expand: () => modalRef.current?.expand(),
|
|
110
|
+
collapse: () => modalRef.current?.collapse(),
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<GorhomBottomSheetModal
|
|
115
|
+
ref={modalRef}
|
|
116
|
+
index={-1}
|
|
117
|
+
snapPoints={config.snapPoints}
|
|
118
|
+
enableDynamicSizing={config.enableDynamicSizing}
|
|
119
|
+
backdropComponent={renderBackdrop}
|
|
120
|
+
keyboardBehavior={config.keyboardBehavior}
|
|
121
|
+
enableHandlePanningGesture={config.enableHandleIndicator}
|
|
122
|
+
enablePanDownToClose={config.enablePanDownToClose}
|
|
123
|
+
onChange={handleSheetChange}
|
|
124
|
+
onDismiss={onDismiss}
|
|
125
|
+
backgroundStyle={[styles.background, { backgroundColor: backgroundColor || tokens.colors.surface }]}
|
|
126
|
+
handleIndicatorStyle={[styles.handleIndicator, { backgroundColor: tokens.colors.border }]}
|
|
127
|
+
>
|
|
128
|
+
<BottomSheetView style={styles.contentContainer}>
|
|
129
|
+
{children}
|
|
130
|
+
</BottomSheetView>
|
|
131
|
+
</GorhomBottomSheetModal>
|
|
132
|
+
);
|
|
133
|
+
});
|
|
271
134
|
|
|
272
135
|
BottomSheetModal.displayName = 'BottomSheetModal';
|
|
273
136
|
|
|
@@ -285,4 +148,3 @@ const styles = StyleSheet.create({
|
|
|
285
148
|
flex: 1,
|
|
286
149
|
},
|
|
287
150
|
});
|
|
288
|
-
|