1- import { createElement , ReactNode , ReactElement , useCallback , useState , useRef , Children } from "react" ;
1+ import { createElement , ReactNode , ReactElement , useCallback , useState , useRef , Children , useMemo } from "react" ;
22import { Dimensions , LayoutChangeEvent , SafeAreaView , StyleSheet , View } from "react-native" ;
33import BottomSheet , { BottomSheetView } from "@gorhom/bottom-sheet" ;
44import { BottomSheetStyle } from "../ui/Styles" ;
@@ -26,23 +26,29 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
2626 const isSmallContentValid = Children . count ( props . smallContent ) > 0 ;
2727 const isLargeContentValid = Children . count ( props . largeContent ) > 0 ;
2828
29- const onLayoutHandlerHeader = ( event : LayoutChangeEvent ) : void => {
30- const height = event . nativeEvent . layout . height ;
31- if ( height > 0 && height <= maxHeight ) {
32- setHeightHeader ( height ) ;
33- }
34- } ;
29+ const onLayoutHandlerHeader = useCallback (
30+ ( event : LayoutChangeEvent ) : void => {
31+ const height = event . nativeEvent . layout . height ;
32+ if ( height > 0 && height <= maxHeight ) {
33+ setHeightHeader ( height ) ;
34+ }
35+ } ,
36+ [ maxHeight ]
37+ ) ;
3538
36- const onLayoutHandlerContent = ( event : LayoutChangeEvent ) : void => {
37- const height = event . nativeEvent . layout . height ;
38- if ( height > 0 ) {
39- if ( height <= maxHeight ) {
40- setHeightContent ( height ) ;
41- } else if ( ! props . fullscreenContent ) {
42- setHeightContent ( maxHeight ) ;
39+ const onLayoutHandlerContent = useCallback (
40+ ( event : LayoutChangeEvent ) : void => {
41+ const height = event . nativeEvent . layout . height ;
42+ if ( height > 0 ) {
43+ if ( height <= maxHeight ) {
44+ setHeightContent ( height ) ;
45+ } else if ( ! props . fullscreenContent ) {
46+ setHeightContent ( maxHeight ) ;
47+ }
4348 }
44- }
45- } ;
49+ } ,
50+ [ maxHeight , props . fullscreenContent ]
51+ ) ;
4652
4753 const onLayoutFullscreenHandler = ( event : LayoutChangeEvent ) : void => {
4854 const height = event . nativeEvent . layout . height ;
@@ -54,6 +60,19 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
5460 const containerStyle =
5561 props . fullscreenContent && isOpen ? props . styles . containerWhenExpandedFullscreen : props . styles . container ;
5662
63+ const snapPoints = useMemo ( ( ) => {
64+ if ( props . fullscreenContent && heightContent ) {
65+ return [ fullscreenHeight , heightContent , heightHeader ] ;
66+ }
67+ if ( props . fullscreenContent ) {
68+ return [ fullscreenHeight , heightHeader ] ;
69+ }
70+ if ( isLargeContentValid ) {
71+ return [ heightContent , heightHeader ] ;
72+ }
73+ return [ heightHeader ] ;
74+ } , [ props . fullscreenContent , heightContent , fullscreenHeight , heightHeader , isLargeContentValid ] ) ;
75+
5776 const renderContent = useCallback ( ( ) : ReactNode => {
5877 const content = (
5978 < View onLayout = { onLayoutHandlerContent } pointerEvents = "box-none" >
@@ -77,7 +96,15 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
7796 ) ;
7897 }
7998 return content ;
80- } , [ props . smallContent , props . largeContent , props . fullscreenContent , isOpen , fullscreenHeight ] ) ;
99+ } , [
100+ props . smallContent ,
101+ props . largeContent ,
102+ props . fullscreenContent ,
103+ fullscreenHeight ,
104+ isSmallContentValid ,
105+ onLayoutHandlerContent ,
106+ onLayoutHandlerHeader
107+ ] ) ;
81108
82109 if ( props . fullscreenContent && fullscreenHeight === 0 ) {
83110 return (
@@ -91,18 +118,9 @@ export const ExpandingDrawer = (props: ExpandingDrawerProps): ReactElement => {
91118 return < View style = { { position : "absolute" , bottom : - maxHeight } } > { renderContent ( ) } </ View > ;
92119 }
93120
94- const snapPoints =
95- props . fullscreenContent && heightContent
96- ? [ fullscreenHeight , heightContent , heightHeader ]
97- : props . fullscreenContent
98- ? [ fullscreenHeight , heightHeader ]
99- : isLargeContentValid
100- ? [ heightContent , heightHeader ]
101- : [ heightHeader ] ;
102-
103121 const collapsedIndex = 0 ;
104122
105- const onChange = ( index : number ) => {
123+ const onChange = ( index : number ) : void => {
106124 const hasOpened = lastIndexRef === - 1 && index === 0 ;
107125 const hasClosed = index === - 1 ;
108126
0 commit comments