@@ -41,6 +41,11 @@ type Props = {
41
41
*/
42
42
enabledContentTapInteraction ?: boolean
43
43
44
+ /**
45
+ * When true, clamp bottom position to first snapPoint.
46
+ */
47
+ enabledBottomClamp ?: boolean
48
+
44
49
/**
45
50
* If false blocks snapping using snapTo method. Defaults to true.
46
51
*/
@@ -286,6 +291,7 @@ export default class BottomSheetBehavior extends React.Component<Props, State> {
286
291
initialSnap : 0 ,
287
292
enabledImperativeSnapping : true ,
288
293
enabledGestureInteraction : true ,
294
+ enabledBottomClamp : false ,
289
295
enabledHeaderGestureInteraction : true ,
290
296
enabledContentGestureInteraction : true ,
291
297
enabledContentTapInteraction : true ,
@@ -317,6 +323,7 @@ export default class BottomSheetBehavior extends React.Component<Props, State> {
317
323
private tapRef : React . RefObject < TapGestureHandler >
318
324
private snapPoint : Animated . Node < number >
319
325
private Y : Animated . Node < number >
326
+ private clampingValue : Animated . Value < number > = new Value ( 0 )
320
327
private onOpenStartValue : Animated . Value < number > = new Value ( 0 )
321
328
private onOpenEndValue : Animated . Value < number > = new Value ( 0 )
322
329
private onCloseStartValue : Animated . Value < number > = new Value ( 1 )
@@ -358,6 +365,10 @@ export default class BottomSheetBehavior extends React.Component<Props, State> {
358
365
// current snap point desired
359
366
this . snapPoint = currentSnapPoint ( )
360
367
368
+ if ( props . enabledBottomClamp ) {
369
+ this . clampingValue . setValue ( snapPoints [ snapPoints . length - 1 ] )
370
+ }
371
+
361
372
const masterClock = new Clock ( )
362
373
const prevMasterDrag = new Value ( 0 )
363
374
const wasRun : Animated . Value < number > = new Value ( 0 )
@@ -406,7 +417,14 @@ export default class BottomSheetBehavior extends React.Component<Props, State> {
406
417
) ,
407
418
cond (
408
419
greaterThan ( masterOffseted , snapPoints [ 0 ] ) ,
409
- masterOffseted ,
420
+ cond (
421
+ and (
422
+ props . enabledBottomClamp ? 1 : 0 ,
423
+ greaterThan ( masterOffseted , this . clampingValue )
424
+ ) ,
425
+ this . clampingValue ,
426
+ masterOffseted
427
+ ) ,
410
428
max (
411
429
multiply (
412
430
sub (
@@ -432,6 +450,13 @@ export default class BottomSheetBehavior extends React.Component<Props, State> {
432
450
)
433
451
}
434
452
453
+ componentDidUpdate ( _prevProps : Props , prevState : State ) {
454
+ const { snapPoints } = this . state
455
+ if ( this . props . enabledBottomClamp && snapPoints !== prevState . snapPoints ) {
456
+ this . clampingValue . setValue ( snapPoints [ snapPoints . length - 1 ] )
457
+ }
458
+ }
459
+
435
460
private runSpring (
436
461
clock : Animated . Clock ,
437
462
value : Animated . Value < number > ,
0 commit comments