@@ -3,9 +3,10 @@ import {
33 BottomSheetModalProps ,
44 BottomSheetModalProvider ,
55 BottomSheetView as RNBottomSheetView ,
6- useBottomSheetDynamicSnapPoints ,
76} from '@gorhom/bottom-sheet' ;
87import { ParamListBase , useTheme } from '@react-navigation/native' ;
8+ import { FullWindowOverlay } from 'react-native-screens' ;
9+ import { SafeAreaProvider } from 'react-native-safe-area-context' ;
910import * as React from 'react' ;
1011import type {
1112 BottomSheetDescriptorMap ,
@@ -15,40 +16,15 @@ import type {
1516 BottomSheetNavigationState ,
1617} from './types' ;
1718
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-
4419type BottomSheetModalScreenProps = BottomSheetModalProps & {
4520 navigation : BottomSheetNavigationProp < ParamListBase > ;
4621} ;
4722
4823function BottomSheetModalScreen ( {
4924 index,
5025 navigation,
51- snapPoints,
26+ enableDynamicSizing,
27+ children,
5228 ...props
5329} : BottomSheetModalScreenProps ) {
5430 const ref = React . useRef < BottomSheetModal > ( null ) ;
@@ -90,19 +66,21 @@ function BottomSheetModalScreen({
9066 }
9167 } , [ navigation ] ) ;
9268
93- const BottomSheetComponent = snapPoints . includes ( 'CONTENT_HEIGHT' )
94- ? DynamicContentHeightBottomSheet
95- : BottomSheetModal ;
96-
9769 return (
98- < BottomSheetComponent
70+ < BottomSheetModal
9971 ref = { ref }
10072 index = { index }
101- snapPoints = { snapPoints }
73+ enableDynamicSizing = { enableDynamicSizing }
10274 onChange = { onChange }
10375 onDismiss = { onDismiss }
10476 { ...props }
105- />
77+ >
78+ { enableDynamicSizing ? (
79+ < RNBottomSheetView > { children as React . ReactNode } </ RNBottomSheetView >
80+ ) : (
81+ children
82+ ) }
83+ </ BottomSheetModal >
10684 ) ;
10785}
10886
@@ -139,43 +117,53 @@ export function BottomSheetView({ state, descriptors }: Props) {
139117 return (
140118 < >
141119 { 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,
169130 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 >
179167 </ >
180168 ) ;
181169}
0 commit comments