@@ -3,9 +3,10 @@ import {
3
3
BottomSheetModalProps ,
4
4
BottomSheetModalProvider ,
5
5
BottomSheetView as RNBottomSheetView ,
6
- useBottomSheetDynamicSnapPoints ,
7
6
} from '@gorhom/bottom-sheet' ;
8
7
import { ParamListBase , useTheme } from '@react-navigation/native' ;
8
+ import { FullWindowOverlay } from 'react-native-screens' ;
9
+ import { SafeAreaProvider } from 'react-native-safe-area-context' ;
9
10
import * as React from 'react' ;
10
11
import type {
11
12
BottomSheetDescriptorMap ,
@@ -15,40 +16,15 @@ import type {
15
16
BottomSheetNavigationState ,
16
17
} from './types' ;
17
18
18
- const DynamicContentHeightBottomSheet = React . forwardRef <
19
- BottomSheetModal ,
20
- BottomSheetModalProps
21
- > ( ( { snapPoints, children, ...props } , ref ) => {
22
- const {
23
- animatedHandleHeight,
24
- animatedSnapPoints,
25
- animatedContentHeight,
26
- handleContentLayout,
27
- } = useBottomSheetDynamicSnapPoints ( snapPoints ) ;
28
-
29
- return (
30
- < BottomSheetModal
31
- ref = { ref }
32
- contentHeight = { animatedContentHeight }
33
- handleHeight = { animatedHandleHeight }
34
- snapPoints = { animatedSnapPoints }
35
- { ...props }
36
- >
37
- < RNBottomSheetView onLayout = { handleContentLayout } >
38
- { children }
39
- </ RNBottomSheetView >
40
- </ BottomSheetModal >
41
- ) ;
42
- } ) ;
43
-
44
19
type BottomSheetModalScreenProps = BottomSheetModalProps & {
45
20
navigation : BottomSheetNavigationProp < ParamListBase > ;
46
21
} ;
47
22
48
23
function BottomSheetModalScreen ( {
49
24
index,
50
25
navigation,
51
- snapPoints,
26
+ enableDynamicSizing,
27
+ children,
52
28
...props
53
29
} : BottomSheetModalScreenProps ) {
54
30
const ref = React . useRef < BottomSheetModal > ( null ) ;
@@ -90,19 +66,21 @@ function BottomSheetModalScreen({
90
66
}
91
67
} , [ navigation ] ) ;
92
68
93
- const BottomSheetComponent = snapPoints . includes ( 'CONTENT_HEIGHT' )
94
- ? DynamicContentHeightBottomSheet
95
- : BottomSheetModal ;
96
-
97
69
return (
98
- < BottomSheetComponent
70
+ < BottomSheetModal
99
71
ref = { ref }
100
72
index = { index }
101
- snapPoints = { snapPoints }
73
+ enableDynamicSizing = { enableDynamicSizing }
102
74
onChange = { onChange }
103
75
onDismiss = { onDismiss }
104
76
{ ...props }
105
- />
77
+ >
78
+ { enableDynamicSizing ? (
79
+ < RNBottomSheetView > { children as React . ReactNode } </ RNBottomSheetView >
80
+ ) : (
81
+ children
82
+ ) }
83
+ </ BottomSheetModal >
106
84
) ;
107
85
}
108
86
@@ -139,43 +117,53 @@ export function BottomSheetView({ state, descriptors }: Props) {
139
117
return (
140
118
< >
141
119
{ firstScreen . render ( ) }
142
- { shouldRenderProvider . current && (
143
- < BottomSheetModalProvider >
144
- { state . routes . slice ( 1 ) . map ( ( route ) => {
145
- const { options, navigation, render } = descriptors [ route . key ] ;
146
-
147
- const {
148
- index,
149
- backgroundStyle,
150
- handleIndicatorStyle,
151
- snapPoints = DEFAULT_SNAP_POINTS ,
152
- ...sheetProps
153
- } = options ;
154
-
155
- return (
156
- < BottomSheetModalScreen
157
- key = { route . key }
158
- // Make sure index is in range, it could be out if snapToIndex is persisted
159
- // and snapPoints is changed.
160
- index = { Math . min (
161
- route . snapToIndex ?? index ?? 0 ,
162
- snapPoints . length - 1 ,
163
- ) }
164
- snapPoints = { snapPoints }
165
- navigation = { navigation }
166
- backgroundStyle = { [ themeBackgroundStyle , backgroundStyle ] }
167
- handleIndicatorStyle = { [
168
- themeHandleIndicatorStyle ,
120
+ < FullWindowOverlay >
121
+ < SafeAreaProvider style = { { flex : 1 , pointerEvents : 'box-none' } } >
122
+ { shouldRenderProvider . current && (
123
+ < BottomSheetModalProvider >
124
+ { state . routes . slice ( 1 ) . map ( ( route ) => {
125
+ const { options, navigation, render } = descriptors [ route . key ] ;
126
+
127
+ const {
128
+ index,
129
+ backgroundStyle,
169
130
handleIndicatorStyle,
170
- ] }
171
- { ...sheetProps }
172
- >
173
- { render ( ) }
174
- </ BottomSheetModalScreen >
175
- ) ;
176
- } ) }
177
- </ BottomSheetModalProvider >
178
- ) }
131
+ snapPoints,
132
+ enableDynamicSizing,
133
+ ...sheetProps
134
+ } = options ;
135
+
136
+ return (
137
+ < BottomSheetModalScreen
138
+ key = { route . key }
139
+ // Make sure index is in range, it could be out if snapToIndex is persisted
140
+ // and snapPoints is changed.
141
+ index = { Math . min (
142
+ route . snapToIndex ?? index ?? 0 ,
143
+ snapPoints != null ? snapPoints . length - 1 : 0 ,
144
+ ) }
145
+ snapPoints = {
146
+ snapPoints == null && ! enableDynamicSizing
147
+ ? DEFAULT_SNAP_POINTS
148
+ : snapPoints
149
+ }
150
+ enableDynamicSizing = { enableDynamicSizing }
151
+ navigation = { navigation }
152
+ backgroundStyle = { [ themeBackgroundStyle , backgroundStyle ] }
153
+ handleIndicatorStyle = { [
154
+ themeHandleIndicatorStyle ,
155
+ handleIndicatorStyle ,
156
+ ] }
157
+ { ...sheetProps }
158
+ >
159
+ { render ( ) }
160
+ </ BottomSheetModalScreen >
161
+ ) ;
162
+ } ) }
163
+ </ BottomSheetModalProvider >
164
+ ) }
165
+ </ SafeAreaProvider >
166
+ </ FullWindowOverlay >
179
167
</ >
180
168
) ;
181
169
}
0 commit comments