@@ -15,13 +15,37 @@ import type {
15
15
BottomSheetNavigationState ,
16
16
} from './types' ;
17
17
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
+
18
44
type BottomSheetModalScreenProps = BottomSheetModalProps & {
19
45
navigation : BottomSheetNavigationProp < ParamListBase > ;
20
46
} ;
21
47
22
48
function BottomSheetModalScreen ( {
23
- contentHeight,
24
- handleHeight,
25
49
index,
26
50
navigation,
27
51
snapPoints,
@@ -66,11 +90,13 @@ function BottomSheetModalScreen({
66
90
}
67
91
} , [ navigation ] ) ;
68
92
93
+ const BottomSheetComponent = snapPoints . includes ( 'CONTENT_HEIGHT' )
94
+ ? DynamicContentHeightBottomSheet
95
+ : BottomSheetModal ;
96
+
69
97
return (
70
- < BottomSheetModal
98
+ < BottomSheetComponent
71
99
ref = { ref }
72
- contentHeight = { contentHeight }
73
- handleHeight = { handleHeight }
74
100
index = { index }
75
101
snapPoints = { snapPoints }
76
102
onChange = { onChange }
@@ -80,14 +106,14 @@ function BottomSheetModalScreen({
80
106
) ;
81
107
}
82
108
109
+ const DEFAULT_SNAP_POINTS = [ '66%' ] ;
110
+
83
111
type Props = BottomSheetNavigationConfig & {
84
112
state : BottomSheetNavigationState < ParamListBase > ;
85
113
navigation : BottomSheetNavigationHelpers ;
86
114
descriptors : BottomSheetDescriptorMap ;
87
115
} ;
88
116
89
- const initialDynamicSnapPoints = [ 'CONTENT_HEIGHT' , 'CONTENT_HEIGHT' ] ;
90
-
91
117
export function BottomSheetView ( { state, descriptors } : Props ) {
92
118
const { colors } = useTheme ( ) ;
93
119
const themeBackgroundStyle = React . useMemo (
@@ -110,13 +136,6 @@ export function BottomSheetView({ state, descriptors }: Props) {
110
136
111
137
const firstScreen = descriptors [ state . routes [ 0 ] . key ] ;
112
138
113
- const {
114
- animatedHandleHeight,
115
- animatedSnapPoints,
116
- animatedContentHeight,
117
- handleContentLayout,
118
- } = useBottomSheetDynamicSnapPoints ( initialDynamicSnapPoints ) ;
119
-
120
139
return (
121
140
< >
122
141
{ firstScreen . render ( ) }
@@ -129,7 +148,7 @@ export function BottomSheetView({ state, descriptors }: Props) {
129
148
index,
130
149
backgroundStyle,
131
150
handleIndicatorStyle,
132
- snapPoints = animatedSnapPoints . value ,
151
+ snapPoints = DEFAULT_SNAP_POINTS ,
133
152
...sheetProps
134
153
} = options ;
135
154
@@ -142,8 +161,6 @@ export function BottomSheetView({ state, descriptors }: Props) {
142
161
route . snapToIndex ?? index ?? 0 ,
143
162
snapPoints . length - 1 ,
144
163
) }
145
- contentHeight = { animatedContentHeight }
146
- handleHeight = { animatedHandleHeight }
147
164
snapPoints = { snapPoints }
148
165
navigation = { navigation }
149
166
backgroundStyle = { [ themeBackgroundStyle , backgroundStyle ] }
@@ -153,9 +170,7 @@ export function BottomSheetView({ state, descriptors }: Props) {
153
170
] }
154
171
{ ...sheetProps }
155
172
>
156
- < RNBottomSheetView onLayout = { handleContentLayout } >
157
- { render ( ) }
158
- </ RNBottomSheetView >
173
+ { render ( ) }
159
174
</ BottomSheetModalScreen >
160
175
) ;
161
176
} ) }
0 commit comments