@@ -51,6 +51,7 @@ import {
51
51
KEYBOARD_BLUR_BEHAVIOR ,
52
52
KEYBOARD_INPUT_MODE ,
53
53
ANIMATION_SOURCE ,
54
+ SNAP_POINT_TYPE ,
54
55
} from '../../constants' ;
55
56
import {
56
57
animate ,
@@ -74,6 +75,7 @@ import {
74
75
DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE ,
75
76
INITIAL_CONTAINER_OFFSET ,
76
77
INITIAL_VALUE ,
78
+ DEFAULT_DYNAMIC_SIZING ,
77
79
} from './constants' ;
78
80
import type { BottomSheetMethods , Insets } from '../../types' ;
79
81
import type { BottomSheetProps , AnimateToPositionType } from './types' ;
@@ -104,6 +106,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
104
106
enableHandlePanningGesture = DEFAULT_ENABLE_HANDLE_PANNING_GESTURE ,
105
107
enableOverDrag = DEFAULT_ENABLE_OVER_DRAG ,
106
108
enablePanDownToClose = DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE ,
109
+ enableDynamicSizing = DEFAULT_DYNAMIC_SIZING ,
107
110
overDragResistanceFactor = DEFAULT_OVER_DRAG_RESISTANCE_FACTOR ,
108
111
109
112
// styles
@@ -122,12 +125,11 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
122
125
android_keyboardInputMode = DEFAULT_KEYBOARD_INPUT_MODE ,
123
126
124
127
// layout
125
- handleHeight : _providedHandleHeight ,
126
128
containerHeight : _providedContainerHeight ,
127
- contentHeight : _providedContentHeight ,
128
129
containerOffset : _providedContainerOffset ,
129
130
topInset = 0 ,
130
131
bottomInset = 0 ,
132
+ maxDynamicContentSize,
131
133
132
134
// animated callback shared values
133
135
animatedPosition : _providedAnimatedPosition ,
@@ -181,17 +183,20 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
181
183
const animatedContainerOffset = useReactiveSharedValue (
182
184
_providedContainerOffset ?? INITIAL_CONTAINER_OFFSET
183
185
) as Animated . SharedValue < Insets > ;
184
- const animatedHandleHeight = useReactiveSharedValue (
185
- _providedHandleHeight ?? INITIAL_HANDLE_HEIGHT
186
+ const animatedHandleHeight = useReactiveSharedValue < number > (
187
+ INITIAL_HANDLE_HEIGHT
186
188
) ;
187
189
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
+ ) ;
195
200
const animatedHighestSnapPoint = useDerivedValue (
196
201
( ) => animatedSnapPoints . value [ animatedSnapPoints . value . length - 1 ]
197
202
) ;
@@ -232,14 +237,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
232
237
}
233
238
234
239
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
- }
243
240
// handle component is null.
244
241
if ( handleComponent === null ) {
245
242
animatedHandleHeight . value = 0 ;
@@ -388,7 +385,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
388
385
return SCROLLABLE_STATE . LOCKED ;
389
386
} ) ;
390
387
// dynamic
391
- const animatedContentHeight = useDerivedValue ( ( ) => {
388
+ const animatedContentHeightMax = useDerivedValue ( ( ) => {
392
389
const keyboardHeightInContainer = animatedKeyboardHeightInContainer . value ;
393
390
const handleHeight = Math . max ( 0 , animatedHandleHeight . value ) ;
394
391
let contentHeight = animatedSheetHeight . value - handleHeight ;
@@ -590,7 +587,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
590
587
]
591
588
) ;
592
589
const handleOnChange = useCallback (
593
- function handleOnChange ( index : number ) {
590
+ function handleOnChange ( index : number , position : number ) {
594
591
print ( {
595
592
component : BottomSheet . name ,
596
593
method : handleOnChange . name ,
@@ -601,10 +598,16 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
601
598
} ) ;
602
599
603
600
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
+ ) ;
605
608
}
606
609
} ,
607
- [ _providedOnChange , animatedCurrentIndex ]
610
+ [ _providedOnChange , animatedCurrentIndex , animatedDynamicSnapPointIndex ]
608
611
) ;
609
612
const handleOnAnimate = useCallback (
610
613
function handleOnAnimate ( toPoint : number ) {
@@ -854,9 +857,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
854
857
*/
855
858
const nextPosition = normalizeSnapPoint (
856
859
position ,
857
- animatedContainerHeight . value ,
858
- topInset ,
859
- bottomInset
860
+ animatedContainerHeight . value
860
861
) ;
861
862
862
863
/**
@@ -1101,6 +1102,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1101
1102
const internalContextVariables = useMemo (
1102
1103
( ) => ( {
1103
1104
enableContentPanningGesture,
1105
+ enableDynamicSizing,
1104
1106
overDragResistanceFactor,
1105
1107
enableOverDrag,
1106
1108
enablePanDownToClose,
@@ -1168,6 +1170,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1168
1170
overDragResistanceFactor ,
1169
1171
enableOverDrag ,
1170
1172
enablePanDownToClose ,
1173
+ enableDynamicSizing ,
1171
1174
_providedSimultaneousHandlers ,
1172
1175
_providedWaitFor ,
1173
1176
_providedActiveOffsetX ,
@@ -1223,20 +1226,23 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1223
1226
) ;
1224
1227
const contentContainerAnimatedStyle = useAnimatedStyle ( ( ) => {
1225
1228
/**
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 .
1228
1231
*/
1229
- if ( _providedContentHeight ) {
1232
+ if (
1233
+ enableDynamicSizing &&
1234
+ animatedContentHeight . value === INITIAL_CONTAINER_HEIGHT
1235
+ ) {
1230
1236
return { } ;
1231
1237
}
1232
1238
1233
1239
return {
1234
1240
height : animate ( {
1235
- point : animatedContentHeight . value ,
1241
+ point : animatedContentHeightMax . value ,
1236
1242
configs : _providedAnimationConfigs ,
1237
1243
} ) ,
1238
1244
} ;
1239
- } , [ animatedContentHeight , _providedContentHeight ] ) ;
1245
+ } , [ animatedContentHeightMax , enableDynamicSizing , animatedContentHeight ] ) ;
1240
1246
const contentContainerStyle = useMemo (
1241
1247
( ) => [ styles . contentContainer , contentContainerAnimatedStyle ] ,
1242
1248
[ contentContainerAnimatedStyle ]
@@ -1620,7 +1626,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1620
1626
} ) ;
1621
1627
1622
1628
animatedCurrentIndex . value = _animatedIndex ;
1623
- runOnJS ( handleOnChange ) ( _animatedIndex ) ;
1629
+ runOnJS ( handleOnChange ) ( _animatedIndex , _animatedPosition ) ;
1624
1630
}
1625
1631
1626
1632
/**
0 commit comments