@@ -15,13 +15,37 @@ import type {
1515 BottomSheetNavigationState ,
1616} from './types' ;
1717
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+
1844type BottomSheetModalScreenProps = BottomSheetModalProps & {
1945 navigation : BottomSheetNavigationProp < ParamListBase > ;
2046} ;
2147
2248function BottomSheetModalScreen ( {
23- contentHeight,
24- handleHeight,
2549 index,
2650 navigation,
2751 snapPoints,
@@ -66,11 +90,13 @@ function BottomSheetModalScreen({
6690 }
6791 } , [ navigation ] ) ;
6892
93+ const BottomSheetComponent = snapPoints . includes ( 'CONTENT_HEIGHT' )
94+ ? DynamicContentHeightBottomSheet
95+ : BottomSheetModal ;
96+
6997 return (
70- < BottomSheetModal
98+ < BottomSheetComponent
7199 ref = { ref }
72- contentHeight = { contentHeight }
73- handleHeight = { handleHeight }
74100 index = { index }
75101 snapPoints = { snapPoints }
76102 onChange = { onChange }
@@ -80,14 +106,14 @@ function BottomSheetModalScreen({
80106 ) ;
81107}
82108
109+ const DEFAULT_SNAP_POINTS = [ '66%' ] ;
110+
83111type Props = BottomSheetNavigationConfig & {
84112 state : BottomSheetNavigationState < ParamListBase > ;
85113 navigation : BottomSheetNavigationHelpers ;
86114 descriptors : BottomSheetDescriptorMap ;
87115} ;
88116
89- const initialDynamicSnapPoints = [ 'CONTENT_HEIGHT' , 'CONTENT_HEIGHT' ] ;
90-
91117export function BottomSheetView ( { state, descriptors } : Props ) {
92118 const { colors } = useTheme ( ) ;
93119 const themeBackgroundStyle = React . useMemo (
@@ -110,13 +136,6 @@ export function BottomSheetView({ state, descriptors }: Props) {
110136
111137 const firstScreen = descriptors [ state . routes [ 0 ] . key ] ;
112138
113- const {
114- animatedHandleHeight,
115- animatedSnapPoints,
116- animatedContentHeight,
117- handleContentLayout,
118- } = useBottomSheetDynamicSnapPoints ( initialDynamicSnapPoints ) ;
119-
120139 return (
121140 < >
122141 { firstScreen . render ( ) }
@@ -129,7 +148,7 @@ export function BottomSheetView({ state, descriptors }: Props) {
129148 index,
130149 backgroundStyle,
131150 handleIndicatorStyle,
132- snapPoints = animatedSnapPoints . value ,
151+ snapPoints = DEFAULT_SNAP_POINTS ,
133152 ...sheetProps
134153 } = options ;
135154
@@ -142,8 +161,6 @@ export function BottomSheetView({ state, descriptors }: Props) {
142161 route . snapToIndex ?? index ?? 0 ,
143162 snapPoints . length - 1 ,
144163 ) }
145- contentHeight = { animatedContentHeight }
146- handleHeight = { animatedHandleHeight }
147164 snapPoints = { snapPoints }
148165 navigation = { navigation }
149166 backgroundStyle = { [ themeBackgroundStyle , backgroundStyle ] }
@@ -153,9 +170,7 @@ export function BottomSheetView({ state, descriptors }: Props) {
153170 ] }
154171 { ...sheetProps }
155172 >
156- < RNBottomSheetView onLayout = { handleContentLayout } >
157- { render ( ) }
158- </ RNBottomSheetView >
173+ { render ( ) }
159174 </ BottomSheetModalScreen >
160175 ) ;
161176 } ) }
0 commit comments