react-native-sheet2 6.1.19 → 7.12.5

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 (110) hide show
  1. package/README.md +754 -80
  2. package/{Sheet.podspec → Sheet2.podspec} +2 -2
  3. package/android/build.gradle +2 -25
  4. package/android/check.jks +0 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
  7. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
  8. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
  9. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
  10. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
  11. package/android/src/main/java/com/sheet2/AppFittedSheet.kt +432 -0
  12. package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
  13. package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
  14. package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +37 -4
  15. package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
  16. package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +170 -0
  17. package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
  18. package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
  19. package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
  20. package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
  21. package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
  22. package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
  23. package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
  24. package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
  25. package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
  26. package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
  27. package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
  28. package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
  29. package/android/src/main/jni/CMakeLists.txt +72 -0
  30. package/android/src/main/jni/SheetViewSpec.h +40 -0
  31. package/ios/FittedSheets/SheetOptions.swift +5 -0
  32. package/ios/FittedSheets/SheetTransition.swift +83 -4
  33. package/ios/FittedSheets/SheetViewController.swift +222 -24
  34. package/ios/HostFittedSheet.swift +440 -51
  35. package/ios/SheetModule.h +5 -4
  36. package/ios/SheetModule.mm +11 -1
  37. package/ios/SheetTreeLog.swift +52 -0
  38. package/ios/SheetView.mm +118 -31
  39. package/ios/SheetViewComponentDescriptor.h +24 -0
  40. package/ios/SheetViewShadowNode.cpp +17 -0
  41. package/ios/SheetViewShadowNode.h +37 -0
  42. package/ios/SheetViewState.h +54 -0
  43. package/package.json +44 -74
  44. package/react-native.config.js +6 -4
  45. package/src/FittedSheet.tsx +131 -71
  46. package/src/GlobalSheetView.tsx +209 -0
  47. package/src/NativeSheet.ts +4 -0
  48. package/src/PublicSheetView.tsx +2 -1
  49. package/src/SheetTreeLog.ts +39 -0
  50. package/src/SheetViewNativeComponent.ts +25 -4
  51. package/src/index.tsx +29 -4
  52. package/src/logger.ts +16 -0
  53. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
  54. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
  55. package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
  56. package/android/generated/jni/CMakeLists.txt +0 -36
  57. package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
  58. package/android/generated/jni/RNSheetViewSpec.h +0 -31
  59. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
  60. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
  61. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
  62. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
  63. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
  64. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
  65. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
  66. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
  67. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
  68. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
  69. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
  70. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
  71. package/android/src/main/AndroidManifestNew.xml +0 -2
  72. package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
  73. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
  74. package/android/src/main/java/com/sheet/SheetView.kt +0 -5
  75. package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
  76. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
  77. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
  78. package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
  79. package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
  80. package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
  81. package/ios/generated/RNSheetViewSpec/Props.h +0 -36
  82. package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
  83. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
  84. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
  85. package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
  86. package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
  87. package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
  88. package/ios/generated/RNSheetViewSpec/States.h +0 -29
  89. package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
  90. package/ios/generated/RNSheetViewSpecJSI.h +0 -98
  91. package/lib/module/FittedSheet.js +0 -153
  92. package/lib/module/FittedSheet.js.map +0 -1
  93. package/lib/module/NativeSheet.ts +0 -17
  94. package/lib/module/PublicSheetView.js +0 -48
  95. package/lib/module/PublicSheetView.js.map +0 -1
  96. package/lib/module/SheetViewNativeComponent.ts +0 -31
  97. package/lib/module/index.js +0 -17
  98. package/lib/module/index.js.map +0 -1
  99. package/lib/module/package.json +0 -1
  100. package/lib/typescript/package.json +0 -1
  101. package/lib/typescript/src/FittedSheet.d.ts +0 -51
  102. package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
  103. package/lib/typescript/src/NativeSheet.d.ts +0 -16
  104. package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
  105. package/lib/typescript/src/PublicSheetView.d.ts +0 -12
  106. package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
  107. package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
  108. package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
  109. package/lib/typescript/src/index.d.ts +0 -12
  110. package/lib/typescript/src/index.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,123 +1,797 @@
1
- # react-native-bottom-sheet
1
+ # react-native-sheet
2
+ ![React Native Bottom Sheet](./preview.gif)
3
+ A high-performance, native bottom sheet component for React Native with auto-sizing and Fabric architecture support.
2
4
 
3
- Native implementation of Bottom sheet
5
+ ## Features
4
6
 
5
- ![React Native Bottom Sheet](./preview.gif)
7
+ - **Native Implementation** - Built with Fabric architecture for iOS and modern Android APIs
8
+ - **Auto-sizing** - Automatically sizes to content height with dynamic updates
9
+ - **Landscape/Portrait Support** - Different constraints for device orientations
10
+ - **Data Passing** - Pass data to sheets and receive values on dismiss
11
+ - **Multiple Sheets** - Support for stacked sheets with named identifiers
12
+ - **Dual APIs** - Both imperative and declarative approaches
13
+ - **Global Sheet API** - Show sheets without pre-declaring components
14
+ - **Customizable** - Control corner radius, colors, sizing constraints
15
+ - **Dismissal Control** - Optional prevention of outside tap dismissal
16
+ - **ScrollView Integration** - Special handling for scrollable content
6
17
 
7
18
  ## Installation
8
19
 
9
20
  ```sh
10
- "react-native-sheet": "sergeymild/react-native-sheet#6.1.10"
21
+ //package.json
22
+ "react-native-sheet":"sergeymild/react-native-sheet#7.0.0"
23
+ yarn
11
24
  ```
12
25
 
13
26
  ## Usage
14
27
 
15
- ```typescript
16
- import {
17
- FittedSheet,
18
- attachScrollViewToFittedSheet,
19
- FittedSheetRef,
20
- presentFittedSheet,
21
- dismissFittedSheetsAll,
22
- dismissFittedPresented,
23
- } from 'react-native-sheet';
24
- import { ScrollView, TouchableOpacity } from 'react-native';
28
+ ### Setup
25
29
 
30
+ Wrap your app with `SheetProvider`:
26
31
 
27
- const RenderSheetComponent: React.FC = () => {
28
- const [isLoading, setLoading] = useState(true)
29
-
30
- useEffect(() => {
31
- setTimeout(() => setLoading(false), 1000)
32
- }, [])
33
-
34
- if (isLoading) {
35
- return <View style={{height: 200}}/>
36
- }
37
-
32
+ ```tsx
33
+ import { SheetProvider } from 'react-native-sheet';
34
+
35
+ export default function App() {
38
36
  return (
39
- // if scrollView creates dynamically in bottom sheet (for example after loading)
40
- // you have call attachScrollViewToFittedSheet to enable nestedScroll
41
- <ScrollView onLayout={() => attachScrollViewToFittedSheet("textSheet")}/>
42
- )
37
+ <SheetProvider>
38
+ <YourApp />
39
+ </SheetProvider>
40
+ );
43
41
  }
42
+ ```
43
+
44
+ #### Logs
45
+
46
+ The library is silent by default. To print its logs, JS and native (iOS and Android), pass `enableLogs`:
47
+
48
+ ```tsx
49
+ <SheetProvider enableLogs>
50
+ <YourApp />
51
+ </SheetProvider>
52
+ ```
44
53
 
45
- const App: React.FC = () => {
54
+ If you don't mount `SheetProvider`, call `setSheetLogsEnabled(true)` (exported from `react-native-sheet`) instead. Warnings such as a duplicate sheet name are also printed only when logs are enabled. The same flag switches the native logs (logcat / unified log) on and off.
55
+
56
+ ### Basic Example
57
+
58
+ ```tsx
59
+ import { FittedSheet, type FittedSheetRef } from 'react-native-sheet';
60
+ import { useRef } from 'react';
61
+ import { View, Text, Button } from 'react-native';
62
+
63
+ export const BasicExample = () => {
46
64
  const sheetRef = useRef<FittedSheetRef>(null);
47
65
 
66
+ return (
67
+ <View>
68
+ <Button
69
+ title="Open Sheet"
70
+ onPress={() => sheetRef.current?.show()}
71
+ />
72
+
73
+ <FittedSheet ref={sheetRef}>
74
+ <View style={{ padding: 20 }}>
75
+ <Text>Hello from Bottom Sheet!</Text>
76
+ <Button
77
+ title="Close"
78
+ onPress={() => sheetRef.current?.hide()}
79
+ />
80
+ </View>
81
+ </FittedSheet>
82
+ </View>
83
+ );
84
+ };
85
+ ```
86
+
87
+ ### Named Sheets (Imperative API)
88
+
89
+ ```tsx
90
+ import {
91
+ FittedSheet,
92
+ presentFittedSheet,
93
+ dismissFittedSheet
94
+ } from 'react-native-sheet';
95
+
96
+ export const NamedExample = () => {
48
97
  return (
49
98
  <>
50
- <TouchableOpacity
99
+ <Button
100
+ title="Open Sheet"
101
+ onPress={() => presentFittedSheet('mySheet')}
102
+ />
103
+
104
+ <FittedSheet name="mySheet">
105
+ <View style={{ padding: 20 }}>
106
+ <Text>Named Sheet</Text>
107
+ <Button
108
+ title="Close"
109
+ onPress={() => dismissFittedSheet('mySheet')}
110
+ />
111
+ </View>
112
+ </FittedSheet>
113
+ </>
114
+ );
115
+ };
116
+ ```
117
+
118
+ ### Global Sheet (Imperative API without Component Declaration)
119
+
120
+ For scenarios where you need to show a sheet without pre-declaring a `FittedSheet` component, you can use the global sheet API:
121
+
122
+ ```tsx
123
+ import {
124
+ presentGlobalFittedSheet,
125
+ dismissGlobalFittedSheet
126
+ } from 'react-native-sheet';
127
+ import { View, Text, Button } from 'react-native';
128
+
129
+ export const GlobalSimpleUsage = () => {
130
+ return (
131
+ <View style={{ flex: 1, padding: 24 }}>
132
+ <Button
133
+ title="Present Global Sheet"
134
+ onPress={() => {
135
+ presentGlobalFittedSheet({
136
+ name: 'myGlobalSheet',
137
+ onDismiss: () => {
138
+ console.log('Sheet dismissed');
139
+ },
140
+ sheetProps: {
141
+ params: {
142
+ backgroundColor: 'white',
143
+ topLeftRightCornerRadius: 10,
144
+ },
145
+ rootViewStyle: {
146
+ paddingBottom: 56,
147
+ },
148
+ },
149
+ children: (
150
+ <View style={{ flexGrow: 1, padding: 20 }}>
151
+ <Text>Global Sheet Content</Text>
152
+ <Button
153
+ title="Dismiss"
154
+ onPress={() => dismissGlobalFittedSheet('myGlobalSheet')}
155
+ />
156
+ </View>
157
+ ),
158
+ });
159
+ }}
160
+ />
161
+
162
+ {/* Dismiss from outside */}
163
+ <Button
164
+ title="Dismiss Global Sheet"
165
+ onPress={() => dismissGlobalFittedSheet('myGlobalSheet')}
166
+ />
167
+ </View>
168
+ );
169
+ };
170
+ ```
171
+
172
+ **Setup**: To enable the global sheet, add the `addGlobalSheetView` prop to `SheetProvider`:
173
+
174
+ ```tsx
175
+ import { SheetProvider } from 'react-native-sheet';
176
+
177
+ export default function App() {
178
+ return (
179
+ <SheetProvider addGlobalSheetView>
180
+ <YourApp />
181
+ </SheetProvider>
182
+ );
183
+ }
184
+ ```
185
+
186
+ You can also provide default sheet properties that will be used for all global sheets:
187
+
188
+ ```tsx
189
+ <SheetProvider
190
+ addGlobalSheetView
191
+ globalSheetProps={{
192
+ params: {
193
+ backgroundColor: '#f5f5f5',
194
+ topLeftRightCornerRadius: 16,
195
+ },
196
+ rootViewStyle: {
197
+ padding: 16,
198
+ },
199
+ }}
200
+ >
201
+ <YourApp />
202
+ </SheetProvider>
203
+ ```
204
+
205
+ #### Advanced Global Sheet Usage
206
+
207
+ **Multiple Global Sheets:**
208
+
209
+ You can present multiple global sheets simultaneously by using unique names:
210
+
211
+ ```tsx
212
+ import {
213
+ presentGlobalFittedSheet,
214
+ dismissGlobalFittedSheet
215
+ } from 'react-native-sheet';
216
+
217
+ // Present first sheet
218
+ presentGlobalFittedSheet({
219
+ name: 'sheet1',
220
+ sheetProps: {
221
+ params: { backgroundColor: 'white' }
222
+ },
223
+ children: (
224
+ <View style={{ padding: 20 }}>
225
+ <Text>First Sheet</Text>
226
+ <Button
227
+ title="Open Second Sheet"
51
228
  onPress={() => {
52
- // show also accept params which will be passed to render function
53
- sheetRef.current?.show()
54
- // or you can call just pass the name of sheet which want to show
55
- // in this case there is no need to store ref on Sheet
56
- presentFittedSheet("textSheet")
229
+ presentGlobalFittedSheet({
230
+ name: 'sheet2',
231
+ sheetProps: {
232
+ params: { backgroundColor: 'lightblue' }
233
+ },
234
+ children: (
235
+ <View style={{ padding: 20 }}>
236
+ <Text>Second Sheet</Text>
237
+ <Button
238
+ title="Dismiss This"
239
+ onPress={() => dismissGlobalFittedSheet('sheet2')}
240
+ />
241
+ <Button
242
+ title="Dismiss First Sheet"
243
+ onPress={() => dismissGlobalFittedSheet('sheet1')}
244
+ />
245
+ </View>
246
+ ),
247
+ });
57
248
  }}
58
- children={<Text children="Show sheet</"/>}
59
249
  />
60
-
61
- <TouchableOpacity
250
+ </View>
251
+ ),
252
+ });
253
+ ```
254
+
255
+ **Dynamic ScrollView in Global Sheet:**
256
+
257
+ When your sheet content loads asynchronously and includes a ScrollView, you need to attach the scrollview after it renders:
258
+
259
+ ```tsx
260
+ import {
261
+ presentGlobalFittedSheet,
262
+ attachScrollViewToGlobalFittedSheet
263
+ } from 'react-native-sheet';
264
+ import { useEffect, useState } from 'react';
265
+ import { ScrollView, ActivityIndicator } from 'react-native';
266
+
267
+ const DynamicContent = ({ sheetName }) => {
268
+ const [loading, setLoading] = useState(true);
269
+ const [data, setData] = useState([]);
270
+
271
+ useEffect(() => {
272
+ // Simulate async data loading
273
+ setTimeout(() => {
274
+ setData(Array.from({ length: 20 }, (_, i) => i + 1));
275
+ setLoading(false);
276
+
277
+ // Attach ScrollView after it appears
278
+ setTimeout(() => {
279
+ attachScrollViewToGlobalFittedSheet(sheetName);
280
+ }, 100);
281
+ }, 2000);
282
+ }, [sheetName]);
283
+
284
+ if (loading) {
285
+ return (
286
+ <View style={{ padding: 40 }}>
287
+ <ActivityIndicator size="large" />
288
+ <Text>Loading data...</Text>
289
+ </View>
290
+ );
291
+ }
292
+
293
+ return (
294
+ <ScrollView style={{ padding: 20 }}>
295
+ <Text>Scrollable Content</Text>
296
+ {data.map(item => (
297
+ <View key={item} style={{ padding: 16 }}>
298
+ <Text>Item {item}</Text>
299
+ </View>
300
+ ))}
301
+ </ScrollView>
302
+ );
303
+ };
304
+
305
+ // Present the sheet
306
+ presentGlobalFittedSheet({
307
+ name: 'dynamicSheet',
308
+ sheetProps: {
309
+ params: {
310
+ backgroundColor: 'white',
311
+ topLeftRightCornerRadius: 10,
312
+ },
313
+ },
314
+ children: <DynamicContent sheetName="dynamicSheet" />,
315
+ });
316
+ ```
317
+
318
+ **Dismissing Multiple Sheets:**
319
+
320
+ ```tsx
321
+ // Dismiss all global sheets at once
322
+ dismissGlobalFittedSheet('sheet1');
323
+ dismissGlobalFittedSheet('sheet2');
324
+ dismissGlobalFittedSheet('sheet3');
325
+ ```
326
+
327
+ **Passing Data to Global Sheets:**
328
+
329
+ Since global sheets don't support the `show(data)` / `hide(returnValue)` pattern, you can pass data using these approaches:
330
+
331
+ ```tsx
332
+ // 1. Pass data via closure/variables
333
+ const userId = 123;
334
+ const userName = 'John Doe';
335
+
336
+ presentGlobalFittedSheet({
337
+ name: 'userProfile',
338
+ children: (
339
+ <View style={{ padding: 20 }}>
340
+ <Text>User ID: {userId}</Text>
341
+ <Text>Name: {userName}</Text>
342
+ </View>
343
+ ),
344
+ });
345
+
346
+ // 2. Return data via closure in onDismiss callback
347
+ let result = null;
348
+
349
+ presentGlobalFittedSheet({
350
+ name: 'confirmDialog',
351
+ onDismiss: () => {
352
+ // Handle the result here
353
+ if (result?.confirmed) {
354
+ console.log('User confirmed!');
355
+ }
356
+ },
357
+ children: (
358
+ <View style={{ padding: 20 }}>
359
+ <Button
360
+ title="Confirm"
361
+ onPress={() => {
362
+ result = { confirmed: true };
363
+ dismissGlobalFittedSheet('confirmDialog');
364
+ }}
365
+ />
366
+ </View>
367
+ ),
368
+ });
369
+
370
+ // 3. Use a component with useState for dynamic data
371
+ const FormSheet = () => {
372
+ const [name, setName] = useState('');
373
+ return (
374
+ <View style={{ padding: 20 }}>
375
+ <TextInput value={name} onChangeText={setName} />
376
+ <Button
377
+ title="Submit"
62
378
  onPress={() => {
63
- // dismiss presented and all in queue sheets without animation
64
- dismissFittedSheetsAll()
65
-
66
- // dismiss top presented sheet
67
- dismissFittedPresented()
379
+ console.log('Submitted:', name);
380
+ dismissGlobalFittedSheet('formSheet');
68
381
  }}
69
- children={<Text children="Dismiss sheet</"/>}
70
382
  />
383
+ </View>
384
+ );
385
+ };
386
+
387
+ presentGlobalFittedSheet({
388
+ name: 'formSheet',
389
+ children: <FormSheet />,
390
+ });
391
+ ```
392
+
393
+ ### Passing Data (FittedSheet with Ref)
394
+
395
+ For `FittedSheet` components with refs, you can pass data using the `show(data)` method and receive return values via `hide(returnValue)`:
396
+
397
+ > **Note**: This pattern only works with `FittedSheet` components that have a ref. For Global Sheets, see the "Passing Data to Global Sheets" section above.
398
+
399
+ ```tsx
400
+ import { FittedSheet, type FittedSheetRef } from 'react-native-sheet';
401
+ import { useRef } from 'react';
402
+
403
+ export const DataExample = () => {
404
+ const sheetRef = useRef<FittedSheetRef>(null);
71
405
 
406
+ const openWithData = () => {
407
+ sheetRef.current?.show({ userId: 123, name: 'John' });
408
+ };
409
+
410
+ return (
411
+ <>
412
+ <Button title="Open Sheet" onPress={openWithData} />
72
413
 
73
414
  <FittedSheet
74
- // can be any string.
75
- // with this name sheet can be dismissed or presented via methods by passing that name
76
- // `presentFittedSheet`, `dismissFittedSheet`
77
- name="textSheet"
78
415
  ref={sheetRef}
79
- onSheetDismiss={(paramsPassedToHideMethod) => {
80
- // called when sheet completely hided
81
- }}
82
- params={{
83
- // if max min should be setted as max height
84
- applyMaxHeightToMinHeight: true | false,
85
- // allow to dismiss
86
- dismissable: false | true,
87
- // top left right corner sheet view radius
88
- topLeftRightCornerRadius: 20,
89
- // background color of sheet view
90
- backgroundColor: 'purple',
91
- // max allowed height of sheet view
92
- maxHeight: 600,
93
- // min height of sheet view
94
- minHeight: 600,
95
- // max allowed width in portrait view
96
- maxPortraitWidth: 300
97
- // max allowed width in landscape view
98
- maxLandscapeWidth: 300,
99
- // should status bar on android be either dark of light
100
- isSystemUILight: false
416
+ onSheetDismiss={(returnValue) => {
417
+ console.log('Sheet dismissed with:', returnValue);
101
418
  }}
102
- >
103
- // data which was passed to .show() method or in presentFittedSheet methods
104
- {(data) => <RenderSheetComponent/>)}
105
- // if you do not need data you can omit render function and pass just component
106
- <RenderSheetComponent/>
419
+ >
420
+ {(data) => (
421
+ <View style={{ padding: 20 }}>
422
+ <Text>User: {data?.name}</Text>
423
+ <Text>ID: {data?.userId}</Text>
424
+ <Button
425
+ title="Close with Result"
426
+ onPress={() => sheetRef.current?.hide({ success: true })}
427
+ />
428
+ </View>
429
+ )}
107
430
  </FittedSheet>
108
431
  </>
109
- )
432
+ );
433
+ };
434
+ ```
435
+
436
+ ### Customization
437
+
438
+ ```tsx
439
+ <FittedSheet
440
+ ref={sheetRef}
441
+ params={{
442
+ maxHeight: 600,
443
+ minHeight: 200,
444
+ maxPortraitWidth: 400,
445
+ maxLandscapeWidth: 600,
446
+ topLeftRightCornerRadius: 24,
447
+ backgroundColor: '#ffffff',
448
+ dismissable: true,
449
+ }}
450
+ rootViewStyle={{ padding: 16 }}
451
+ >
452
+ <YourContent />
453
+ </FittedSheet>
454
+ ```
455
+
456
+ ### Multiple Sheets
457
+
458
+ ```tsx
459
+ export const MultipleExample = () => {
460
+ return (
461
+ <>
462
+ <Button
463
+ title="Open First Sheet"
464
+ onPress={() => presentFittedSheet('first')}
465
+ />
466
+
467
+ <FittedSheet
468
+ name="first"
469
+ params={{ backgroundColor: '#f0f0f0' }}
470
+ >
471
+ <View style={{ padding: 20 }}>
472
+ <Text>First Sheet</Text>
473
+ <Button
474
+ title="Open Second Sheet"
475
+ onPress={() => presentFittedSheet('second')}
476
+ />
477
+ </View>
478
+ </FittedSheet>
479
+
480
+ <FittedSheet
481
+ name="second"
482
+ params={{ backgroundColor: '#e0e0ff' }}
483
+ >
484
+ <View style={{ padding: 20 }}>
485
+ <Text>Second Sheet</Text>
486
+ <Button
487
+ title="Dismiss All"
488
+ onPress={() => dismissFittedSheetsAll()}
489
+ />
490
+ </View>
491
+ </FittedSheet>
492
+ </>
493
+ );
494
+ };
495
+ ```
496
+
497
+ ## API Reference
498
+
499
+ ### FittedSheet Props
500
+
501
+ | Prop | Type | Default | Description |
502
+ |------|------|---------|-------------|
503
+ | `name` | `string` | `undefined` | Optional identifier for imperative API control |
504
+ | `params` | `SheetParams` | `{}` | Configuration options for the sheet |
505
+ | `onSheetDismiss` | `(value?: any) => void` | `undefined` | Callback when sheet is dismissed |
506
+ | `rootViewStyle` | `ViewStyle` | `undefined` | Style for internal root view |
507
+ | `children` | `ReactNode \| ((data?: any) => ReactNode)` | - | Content to render in sheet |
508
+
509
+ ### SheetParams
510
+
511
+ | Param | Type | Default | Description |
512
+ |-------|------|---------|-------------|
513
+ | `applyMaxHeightToMinHeight` | `boolean` | `false` | Apply max height constraint to min height |
514
+ | `dismissable` | `boolean` | `true` | Allow dismissing by tapping outside |
515
+ | `maxPortraitWidth` | `number` | `undefined` | Maximum width in portrait mode |
516
+ | `maxLandscapeWidth` | `number` | `undefined` | Maximum width in landscape mode |
517
+ | `maxHeight` | `number` | `undefined` | Maximum height of sheet |
518
+ | `minHeight` | `number` | `undefined` | Minimum height of sheet |
519
+ | `topLeftRightCornerRadius` | `number` | `20` | Radius for top corners |
520
+ | `backgroundColor` | `string` | `'white'` | Background color of sheet |
521
+ | `isSystemUILight` | `boolean` | `undefined` | Android only - status bar styling |
522
+ | `presentationStyle` | `'bottom' \| 'center' \| 'footer'` | `'bottom'` | `'center'` shows the sheet as a dialog card in the vertical center with a full-screen dim; dismiss by swiping down or tapping the dim. Ignores `useInlinePresentation`. `'footer'` (with `useInlinePresentation`) pins the content to the bottom of the screen above inline sheets, with no gestures or dim — for a buy button that must stay put while an inline sheet is dragged, or for full-screen overlays that must cover it. |
523
+ | `centerAnimation` | `'fade' \| 'slide'` | `'fade'` | Enter animation for `presentationStyle: 'center'`. `'fade'` = fade + scale in; `'slide'` = slide up into center. |
524
+ | `dismissOnOverlayTap` | `boolean` | `dismissable` | Tap on the dimmed background dismisses the sheet. `false` with `dismissable: true` keeps swipe-to-dismiss but ignores taps. |
525
+ | `overlayOpacity` | `number` | platform default | Background dim opacity, 0..1. `0` with `useInlinePresentation` removes the background and lets touches reach the screen behind. |
526
+ | `collapsedHeight` | `number` | — | `useInlinePresentation` only. Lower snap point; the sheet opens there and can be dragged up to its full height. |
527
+
528
+ ### FittedSheetRef Methods
529
+
530
+ ```typescript
531
+ interface FittedSheetRef {
532
+ show(data?: any): void; // Show sheet with optional data
533
+ hide(passThroughParam?: any): void; // Hide sheet with optional callback param
534
+ attachScrollViewToSheet(): void; // Attach scrollview for better scrolling
110
535
  }
111
536
  ```
112
537
 
113
- ## More examples
114
- More detailed examples may be found in `example` project
538
+ ### Imperative API
539
+
540
+ ```typescript
541
+ // Show a named sheet
542
+ presentFittedSheet(name: string, data?: any): void
543
+
544
+ // Hide a specific named sheet
545
+ dismissFittedSheet(name: string, passThroughParam?: any): void
546
+
547
+ // Hide all sheets
548
+ dismissFittedSheetsAll(): void
549
+
550
+ // Hide the most recently presented sheet
551
+ dismissFittedPresented(): void
552
+
553
+ // Attach scrollview to a named sheet
554
+ attachScrollViewToFittedSheet(name: string): void
555
+
556
+ // Global Sheet API - Show a sheet without pre-declaring a component
557
+ presentGlobalFittedSheet(params: {
558
+ name: string;
559
+ onDismiss?: () => void;
560
+ sheetProps?: SheetProps;
561
+ children: ReactElement | ReactElement[];
562
+ }): void
563
+
564
+ // Dismiss a specific global sheet by name
565
+ dismissGlobalFittedSheet(name: string): void
566
+
567
+ // Attach scrollview to a global sheet by name (for dynamic ScrollView content)
568
+ attachScrollViewToGlobalFittedSheet(name: string): boolean
569
+ ```
570
+
571
+ ### SheetProvider Props
572
+
573
+ | Prop | Type | Default | Description |
574
+ |------|------|---------|-------------|
575
+ | `children` | `ReactNode` | - | Your app content |
576
+ | `addGlobalSheetView` | `boolean` | `false` | Enable global sheet API |
577
+ | `globalSheetProps` | `Omit<SheetProps, 'children' \| 'onSheetDismiss'>` | `undefined` | Default props for global sheets |
578
+
579
+ ## Advanced Examples
580
+
581
+ ### Dynamic Content Height
582
+
583
+ The sheet automatically resizes when content height changes:
584
+
585
+ ```tsx
586
+ export const DynamicExample = () => {
587
+ const [items, setItems] = useState([1, 2, 3]);
588
+ const sheetRef = useRef<FittedSheetRef>(null);
589
+
590
+ return (
591
+ <FittedSheet ref={sheetRef}>
592
+ <View style={{ padding: 20 }}>
593
+ {items.map(item => (
594
+ <View key={item} style={{ height: 50, marginBottom: 10 }}>
595
+ <Text>Item {item}</Text>
596
+ </View>
597
+ ))}
598
+ <Button
599
+ title="Add Item"
600
+ onPress={() => setItems([...items, items.length + 1])}
601
+ />
602
+ </View>
603
+ </FittedSheet>
604
+ );
605
+ };
606
+ ```
115
607
 
608
+ ### Preventing Dismissal
609
+
610
+ ```tsx
611
+ <FittedSheet
612
+ ref={sheetRef}
613
+ params={{ dismissable: false }}
614
+ >
615
+ <View style={{ padding: 20 }}>
616
+ <Text>This sheet can't be dismissed by tapping outside</Text>
617
+ <Button
618
+ title="Close"
619
+ onPress={() => sheetRef.current?.hide()}
620
+ />
621
+ </View>
622
+ </FittedSheet>
623
+ ```
624
+
625
+ ### ScrollView Integration
626
+
627
+ When using scrollable content, avoid wrapping in an additional `View`. Use a fragment instead for better performance:
628
+
629
+ ```tsx
630
+ import { ScrollView } from 'react-native';
631
+
632
+ export const ScrollExample = () => {
633
+ const sheetRef = useRef<FittedSheetRef>(null);
634
+
635
+ useEffect(() => {
636
+ // Attach scrollview for better scroll handling
637
+ sheetRef.current?.attachScrollViewToSheet();
638
+ }, []);
639
+
640
+ return (
641
+ <FittedSheet ref={sheetRef}>
642
+ <>
643
+ <ScrollView style={{ maxHeight: 400 }}>
644
+ {/* Your scrollable content */}
645
+ </ScrollView>
646
+ </>
647
+ </FittedSheet>
648
+ );
649
+ };
650
+ ```
651
+
652
+ **Important:** When using `ScrollView`, `FlatList`, or other scrollable components, do not wrap them in an additional `View`:
653
+
654
+ ```tsx
655
+ // ✅ Good - use fragment
656
+ <FittedSheet ref={sheetRef}>
657
+ <>
658
+ <ScrollView>...</ScrollView>
659
+ </>
660
+ </FittedSheet>
661
+
662
+ // ❌ Bad - avoid extra View wrapper
663
+ <FittedSheet ref={sheetRef}>
664
+ <View>
665
+ <ScrollView>...</ScrollView>
666
+ </View>
667
+ </FittedSheet>
668
+
669
+ // ⚠️ If you must wrap ScrollView in a View, add flexGrow: 1
670
+ <FittedSheet ref={sheetRef}>
671
+ <View style={{ flexGrow: 1 }}>
672
+ <ScrollView>...</ScrollView>
673
+ </View>
674
+ </FittedSheet>
675
+ ```
676
+
677
+ **Note:** If you need to wrap `ScrollView` in a `View` (e.g., for additional styling), make sure to add `flexGrow: 1` to the wrapper `View` style. This ensures proper height calculation for the sheet content.
678
+
679
+ ### Centered / Tablet Dialog
680
+
681
+ Show the sheet as a centered dialog card (useful for tablets) instead of a
682
+ bottom sheet. The whole screen dims and the card is dismissed by swiping down or
683
+ tapping outside:
684
+
685
+ ```tsx
686
+ <FittedSheet
687
+ ref={sheetRef}
688
+ params={{
689
+ presentationStyle: 'center',
690
+ centerAnimation: 'fade', // or 'slide'
691
+ maxPortraitWidth: 420,
692
+ maxLandscapeWidth: 420,
693
+ backgroundColor: 'white',
694
+ topLeftRightCornerRadius: 20,
695
+ }}
696
+ >
697
+ <YourContent />
698
+ </FittedSheet>
699
+ ```
700
+
701
+ `presentationStyle: 'center'` always presents modally — `useInlinePresentation`
702
+ is ignored in this mode. Your app decides when to enable it (for example, based
703
+ on tablet detection).
704
+
705
+ ## Platform-Specific Notes
706
+
707
+ ### iOS
708
+ - Uses native UIViewController presentation
709
+ - Supports safe area insets automatically
710
+ - Corner radius applied to top-left and top-right corners
711
+
712
+ ### Android
713
+ - Uses Material BottomSheetDialog
714
+ - Supports status bar styling via `isSystemUILight` param
715
+
716
+ ## Requirements
717
+
718
+ - React Native >= 0.70 (Fabric support)
719
+ - iOS >= 12.0
720
+ - Android minSdkVersion >= 21
721
+
722
+ ## Troubleshooting
723
+
724
+ ### Sheet not appearing
725
+ Make sure your app is wrapped with `SheetProvider`:
726
+ ```tsx
727
+ <SheetProvider>
728
+ <App />
729
+ </SheetProvider>
730
+ ```
731
+
732
+ ### Content not resizing
733
+ Ensure your content has proper height constraints or use `flexGrow` instead of `flex: 1`.
734
+
735
+ ### Global sheet not working
736
+ Make sure you've enabled global sheets in `SheetProvider`:
737
+ ```tsx
738
+ <SheetProvider addGlobalSheetView>
739
+ <YourApp />
740
+ </SheetProvider>
741
+ ```
742
+
743
+ ### ScrollView not working in global sheet
744
+ If you're loading ScrollView content asynchronously, you need to attach it after the content renders:
745
+ ```tsx
746
+ attachScrollViewToGlobalFittedSheet('sheetName');
747
+ ```
748
+ This should be called after your ScrollView component has mounted (typically in a `useEffect` hook after data loading completes).
749
+
750
+ ### How to pass data to global sheets?
751
+ Global sheets don't support the `show(data)` / `hide(returnValue)` pattern like FittedSheet with refs. Instead, use closures, variables, or component state:
752
+ - **Pass data in**: Use closure variables or props in the children component
753
+ - **Return data**: Use a closure variable and set it before calling `dismissGlobalFittedSheet`, then handle it in `onDismiss` callback
754
+ - **Dynamic data**: Use a component with `useState` as children
755
+
756
+ See the "Passing Data to Global Sheets" section in the documentation for examples.
757
+
758
+ ## Example App
759
+
760
+ To run the example app:
761
+
762
+ ```sh
763
+ # Install dependencies
764
+ yarn
765
+
766
+ # Run on iOS
767
+ yarn example ios
768
+
769
+ # Run on Android
770
+ yarn example android
771
+ ```
772
+
773
+ The example app includes demonstrations of:
774
+ - Basic usage
775
+ - Named sheets
776
+ - Global sheet API
777
+ - Data passing
778
+ - Multiple sheets
779
+ - Dynamic content
780
+ - ScrollView integration
781
+ - Queue management
782
+ - Custom styling
116
783
 
117
784
  ## Contributing
118
785
 
119
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
786
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on:
787
+ - Development workflow
788
+ - Sending pull requests
789
+ - Code of conduct
120
790
 
121
791
  ## License
122
792
 
123
793
  MIT
794
+
795
+ ---
796
+
797
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)