@@ -32,91 +32,100 @@ export interface BottomSheetProps extends ScrollViewProps {
3232 theme : Theme ;
3333}
3434
35- const BottomSheet : React . FC < React . PropsWithChildren < BottomSheetProps > > = ( {
36- theme,
37- snapPoints : snapPointsProp ,
38- topSnapPosition = "10%" ,
39- middleSnapPosition = "50%" ,
40- bottomSnapPosition = "80%" ,
41- initialSnapIndex,
42- initialSnapPosition = "bottom" ,
43- showHandle = true ,
44- handleColor = theme . colors . divider ,
45- topBorderRadius = 20 ,
46- borderWidth = 1 ,
47- borderColor = theme . colors . divider ,
48- onSettle,
49- style,
50- children,
51- ...rest
52- } ) => {
53- const backgroundColor =
54- ( style as ViewStyle ) ?. backgroundColor || theme . colors . background ;
35+ const BottomSheet = React . forwardRef <
36+ BottomSheetComponent < any > ,
37+ BottomSheetProps
38+ > (
39+ (
40+ {
41+ theme,
42+ snapPoints : snapPointsProp ,
43+ topSnapPosition = "10%" ,
44+ middleSnapPosition = "50%" ,
45+ bottomSnapPosition = "80%" ,
46+ initialSnapIndex,
47+ initialSnapPosition = "bottom" ,
48+ showHandle = true ,
49+ handleColor = theme . colors . divider ,
50+ topBorderRadius = 20 ,
51+ borderWidth = 1 ,
52+ borderColor = theme . colors . divider ,
53+ onSettle,
54+ style,
55+ children,
56+ ...rest
57+ } ,
58+ ref
59+ ) => {
60+ const backgroundColor =
61+ ( style as ViewStyle ) ?. backgroundColor || theme . colors . background ;
5562
56- const snapPoints = snapPointsProp || [
57- topSnapPosition ,
58- middleSnapPosition ,
59- bottomSnapPosition ,
60- ] ;
63+ const snapPoints = snapPointsProp || [
64+ topSnapPosition ,
65+ middleSnapPosition ,
66+ bottomSnapPosition ,
67+ ] ;
6168
62- const getSnapIndexFromPosition = ( position : SnapPosition ) => {
63- switch ( position ) {
64- case "top" :
65- return 0 ;
66- case "middle" :
67- return 1 ;
68- case "bottom" :
69- return 2 ;
70- }
71- } ;
69+ const getSnapIndexFromPosition = ( position : SnapPosition ) => {
70+ switch ( position ) {
71+ case "top" :
72+ return 0 ;
73+ case "middle" :
74+ return 1 ;
75+ case "bottom" :
76+ return 2 ;
77+ }
78+ } ;
7279
73- return (
74- < View style = { styles . parentContainer } pointerEvents = "box-none" >
75- < BottomSheetComponent
76- componentType = "ScrollView"
77- snapPoints = { snapPoints }
78- initialSnapIndex = {
79- initialSnapIndex ?? getSnapIndexFromPosition ( initialSnapPosition )
80- }
81- renderHandle = { ( ) => (
82- < >
83- { showHandle && (
84- < View
85- style = { [
86- styles . handleContainer ,
87- {
88- backgroundColor,
89- borderTopLeftRadius : topBorderRadius ,
90- borderTopRightRadius : topBorderRadius ,
91- } ,
92- ] }
93- >
80+ return (
81+ < View style = { styles . parentContainer } pointerEvents = "box-none" >
82+ < BottomSheetComponent
83+ ref = { ref }
84+ componentType = "ScrollView"
85+ snapPoints = { snapPoints }
86+ initialSnapIndex = {
87+ initialSnapIndex ?? getSnapIndexFromPosition ( initialSnapPosition )
88+ }
89+ renderHandle = { ( ) => (
90+ < >
91+ { showHandle && (
9492 < View
95- style = { [ styles . handle , { backgroundColor : handleColor } ] }
96- />
97- </ View >
98- ) }
99- </ >
100- ) }
101- contentContainerStyle = { [ styles . contentContainerStyle , style ] }
102- containerStyle = { StyleSheet . flatten ( [
103- styles . containerStyle ,
104- {
105- backgroundColor,
106- borderTopLeftRadius : topBorderRadius ,
107- borderTopRightRadius : topBorderRadius ,
108- borderWidth,
109- borderColor,
110- } ,
111- ] ) }
112- onSettle = { onSettle }
113- { ...rest }
114- >
115- { children }
116- </ BottomSheetComponent >
117- </ View >
118- ) ;
119- } ;
93+ style = { [
94+ styles . handleContainer ,
95+ {
96+ backgroundColor,
97+ borderTopLeftRadius : topBorderRadius ,
98+ borderTopRightRadius : topBorderRadius ,
99+ } ,
100+ ] }
101+ >
102+ < View
103+ style = { [ styles . handle , { backgroundColor : handleColor } ] }
104+ />
105+ </ View >
106+ ) }
107+ </ >
108+ ) }
109+ contentContainerStyle = { [ styles . contentContainerStyle , style ] }
110+ containerStyle = { StyleSheet . flatten ( [
111+ styles . containerStyle ,
112+ {
113+ backgroundColor,
114+ borderTopLeftRadius : topBorderRadius ,
115+ borderTopRightRadius : topBorderRadius ,
116+ borderWidth,
117+ borderColor,
118+ } ,
119+ ] ) }
120+ onSettle = { onSettle }
121+ { ...rest }
122+ >
123+ { children }
124+ </ BottomSheetComponent >
125+ </ View >
126+ ) ;
127+ }
128+ ) ;
120129
121130const styles = StyleSheet . create ( {
122131 //Render on top of everything
0 commit comments