@@ -51,6 +51,7 @@ import {
5151 KEYBOARD_BLUR_BEHAVIOR ,
5252 KEYBOARD_INPUT_MODE ,
5353 ANIMATION_SOURCE ,
54+ SNAP_POINT_TYPE ,
5455} from '../../constants' ;
5556import {
5657 animate ,
@@ -74,6 +75,7 @@ import {
7475 DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE ,
7576 INITIAL_CONTAINER_OFFSET ,
7677 INITIAL_VALUE ,
78+ DEFAULT_DYNAMIC_SIZING ,
7779} from './constants' ;
7880import type { BottomSheetMethods , Insets } from '../../types' ;
7981import type { BottomSheetProps , AnimateToPositionType } from './types' ;
@@ -104,6 +106,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
104106 enableHandlePanningGesture = DEFAULT_ENABLE_HANDLE_PANNING_GESTURE ,
105107 enableOverDrag = DEFAULT_ENABLE_OVER_DRAG ,
106108 enablePanDownToClose = DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE ,
109+ enableDynamicSizing = DEFAULT_DYNAMIC_SIZING ,
107110 overDragResistanceFactor = DEFAULT_OVER_DRAG_RESISTANCE_FACTOR ,
108111
109112 // styles
@@ -122,12 +125,11 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
122125 android_keyboardInputMode = DEFAULT_KEYBOARD_INPUT_MODE ,
123126
124127 // layout
125- handleHeight : _providedHandleHeight ,
126128 containerHeight : _providedContainerHeight ,
127- contentHeight : _providedContentHeight ,
128129 containerOffset : _providedContainerOffset ,
129130 topInset = 0 ,
130131 bottomInset = 0 ,
132+ maxDynamicContentSize,
131133
132134 // animated callback shared values
133135 animatedPosition : _providedAnimatedPosition ,
@@ -181,17 +183,20 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
181183 const animatedContainerOffset = useReactiveSharedValue (
182184 _providedContainerOffset ?? INITIAL_CONTAINER_OFFSET
183185 ) as Animated . SharedValue < Insets > ;
184- const animatedHandleHeight = useReactiveSharedValue (
185- _providedHandleHeight ?? INITIAL_HANDLE_HEIGHT
186+ const animatedHandleHeight = useReactiveSharedValue < number > (
187+ INITIAL_HANDLE_HEIGHT
186188 ) ;
187189 const animatedFooterHeight = useSharedValue ( 0 ) ;
188- const animatedSnapPoints = useNormalizedSnapPoints (
189- _providedSnapPoints ,
190- animatedContainerHeight ,
191- topInset ,
192- bottomInset ,
193- $modal
194- ) ;
190+ const animatedContentHeight = useSharedValue ( INITIAL_CONTAINER_HEIGHT ) ;
191+ const [ animatedSnapPoints , animatedDynamicSnapPointIndex ] =
192+ useNormalizedSnapPoints (
193+ _providedSnapPoints ,
194+ animatedContainerHeight ,
195+ animatedContentHeight ,
196+ animatedHandleHeight ,
197+ enableDynamicSizing ,
198+ maxDynamicContentSize
199+ ) ;
195200 const animatedHighestSnapPoint = useDerivedValue (
196201 ( ) => animatedSnapPoints . value [ animatedSnapPoints . value . length - 1 ]
197202 ) ;
@@ -232,14 +237,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
232237 }
233238
234239 let isHandleHeightCalculated = false ;
235- // handle height is provided.
236- if (
237- _providedHandleHeight !== null &&
238- _providedHandleHeight !== undefined &&
239- typeof _providedHandleHeight === 'number'
240- ) {
241- isHandleHeightCalculated = true ;
242- }
243240 // handle component is null.
244241 if ( handleComponent === null ) {
245242 animatedHandleHeight . value = 0 ;
@@ -388,7 +385,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
388385 return SCROLLABLE_STATE . LOCKED ;
389386 } ) ;
390387 // dynamic
391- const animatedContentHeight = useDerivedValue ( ( ) => {
388+ const animatedContentHeightMax = useDerivedValue ( ( ) => {
392389 const keyboardHeightInContainer = animatedKeyboardHeightInContainer . value ;
393390 const handleHeight = Math . max ( 0 , animatedHandleHeight . value ) ;
394391 let contentHeight = animatedSheetHeight . value - handleHeight ;
@@ -590,7 +587,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
590587 ]
591588 ) ;
592589 const handleOnChange = useCallback (
593- function handleOnChange ( index : number ) {
590+ function handleOnChange ( index : number , position : number ) {
594591 print ( {
595592 component : BottomSheet . name ,
596593 method : handleOnChange . name ,
@@ -601,10 +598,16 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
601598 } ) ;
602599
603600 if ( _providedOnChange ) {
604- _providedOnChange ( index ) ;
601+ _providedOnChange (
602+ index ,
603+ position ,
604+ index === animatedDynamicSnapPointIndex . value
605+ ? SNAP_POINT_TYPE . DYNAMIC
606+ : SNAP_POINT_TYPE . PROVIDED
607+ ) ;
605608 }
606609 } ,
607- [ _providedOnChange , animatedCurrentIndex ]
610+ [ _providedOnChange , animatedCurrentIndex , animatedDynamicSnapPointIndex ]
608611 ) ;
609612 const handleOnAnimate = useCallback (
610613 function handleOnAnimate ( toPoint : number ) {
@@ -854,9 +857,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
854857 */
855858 const nextPosition = normalizeSnapPoint (
856859 position ,
857- animatedContainerHeight . value ,
858- topInset ,
859- bottomInset
860+ animatedContainerHeight . value
860861 ) ;
861862
862863 /**
@@ -1101,6 +1102,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
11011102 const internalContextVariables = useMemo (
11021103 ( ) => ( {
11031104 enableContentPanningGesture,
1105+ enableDynamicSizing,
11041106 overDragResistanceFactor,
11051107 enableOverDrag,
11061108 enablePanDownToClose,
@@ -1168,6 +1170,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
11681170 overDragResistanceFactor ,
11691171 enableOverDrag ,
11701172 enablePanDownToClose ,
1173+ enableDynamicSizing ,
11711174 _providedSimultaneousHandlers ,
11721175 _providedWaitFor ,
11731176 _providedActiveOffsetX ,
@@ -1223,20 +1226,23 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
12231226 ) ;
12241227 const contentContainerAnimatedStyle = useAnimatedStyle ( ( ) => {
12251228 /**
1226- * if content height was provided, then we skip setting
1227- * calculated height .
1229+ * if dynamic sizing is enabled, and content height
1230+ * is still not set, then we exit method .
12281231 */
1229- if ( _providedContentHeight ) {
1232+ if (
1233+ enableDynamicSizing &&
1234+ animatedContentHeight . value === INITIAL_CONTAINER_HEIGHT
1235+ ) {
12301236 return { } ;
12311237 }
12321238
12331239 return {
12341240 height : animate ( {
1235- point : animatedContentHeight . value ,
1241+ point : animatedContentHeightMax . value ,
12361242 configs : _providedAnimationConfigs ,
12371243 } ) ,
12381244 } ;
1239- } , [ animatedContentHeight , _providedContentHeight ] ) ;
1245+ } , [ animatedContentHeightMax , enableDynamicSizing , animatedContentHeight ] ) ;
12401246 const contentContainerStyle = useMemo (
12411247 ( ) => [ styles . contentContainer , contentContainerAnimatedStyle ] ,
12421248 [ contentContainerAnimatedStyle ]
@@ -1620,7 +1626,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
16201626 } ) ;
16211627
16221628 animatedCurrentIndex . value = _animatedIndex ;
1623- runOnJS ( handleOnChange ) ( _animatedIndex ) ;
1629+ runOnJS ( handleOnChange ) ( _animatedIndex , _animatedPosition ) ;
16241630 }
16251631
16261632 /**
0 commit comments