@@ -76,12 +76,21 @@ export class PersistentBottomSheet extends GridLayout {
76
76
// isPanning = false;
77
77
backdropColor = null ;
78
78
79
- steps : number [ ] = [ 70 ] ;
79
+ _steps : number [ ] = [ 70 ] ;
80
+
81
+ get steps ( ) {
82
+ const result = this . _steps || ( this . bottomSheet && ( this . bottomSheet as any ) . steps ) ;
83
+ return result ;
84
+ }
85
+ set steps ( value : number [ ] ) {
86
+ this . _steps = value ;
87
+ }
80
88
stepIndex = 0 ;
81
89
82
90
isAnimating = false ;
83
91
prevDeltaY = 0 ;
84
92
viewHeight = 0 ;
93
+ bottomViewHeight = 0 ;
85
94
panGestureHandler : PanGestureHandler ;
86
95
87
96
lastScrollY : number ;
@@ -165,7 +174,8 @@ export class PersistentBottomSheet extends GridLayout {
165
174
this . _translationY = value ;
166
175
}
167
176
get translationMaxOffset ( ) {
168
- return this . steps [ this . steps . length - 1 ] ;
177
+ const steps = this . steps ;
178
+ return steps [ steps . length - 1 ] ;
169
179
}
170
180
initNativeView ( ) {
171
181
super . initNativeView ( ) ;
@@ -271,7 +281,8 @@ export class PersistentBottomSheet extends GridLayout {
271
281
if ( newValue ) {
272
282
newValue . iosOverflowSafeAreaEnabled = false ;
273
283
newValue . verticalAlignment = 'bottom' ;
274
- let index ;
284
+ newValue . on ( 'layoutChanged' , this . onBottomLayoutChange , this ) ;
285
+ let index ;
275
286
if ( ! newValue . parent ) {
276
287
index = this . getChildrenCount ( ) ;
277
288
this . addChild ( newValue ) ;
@@ -287,9 +298,8 @@ export class PersistentBottomSheet extends GridLayout {
287
298
}
288
299
}
289
300
290
- computeTranslationData ( ) {
291
- const value = this . translationY ;
292
- const height = this . translationMaxOffset ;
301
+ computeTranslationData ( height ) {
302
+ const value = this . _translationY ;
293
303
const progress = 1 - value / height ;
294
304
if ( this . translationFunction ) {
295
305
return this . translationFunction ( height , value , progress ) ;
@@ -307,11 +317,27 @@ export class PersistentBottomSheet extends GridLayout {
307
317
const contentView = event . object as GridLayout ;
308
318
const height = Math . round ( Utils . layout . toDeviceIndependentPixels ( contentView . getMeasuredHeight ( ) ) ) ;
309
319
this . viewHeight = height ;
310
- if ( this . translationY === - 1 ) {
311
- const step = this . steps [ this . stepIndex ] ;
312
- const ty = this . translationMaxOffset - step ;
320
+ if ( this . translationY === - 1 && this . bottomViewHeight !== 0 ) {
321
+ const height = this . bottomViewHeight ;
322
+ const steps = this . steps ;
323
+ const step = steps [ this . stepIndex ] ;
324
+ const ty = height - step ;
325
+ this . translationY = ty ;
326
+ const data = this . computeTranslationData ( height ) ;
327
+ this . applyTrData ( data ) ;
328
+ }
329
+ }
330
+ onBottomLayoutChange ( event : EventData ) {
331
+ const contentView = event . object as GridLayout ;
332
+ const height = Math . round ( Utils . layout . toDeviceIndependentPixels ( contentView . getMeasuredHeight ( ) ) ) ;
333
+ this . bottomViewHeight = height ;
334
+ if ( this . translationY === - 1 && this . viewHeight !== 0 ) {
335
+ const height = this . bottomViewHeight ;
336
+ const steps = this . steps ;
337
+ const step = steps [ this . stepIndex ] ;
338
+ const ty = height - step ;
313
339
this . translationY = ty ;
314
- const data = this . computeTranslationData ( ) ;
340
+ const data = this . computeTranslationData ( height ) ;
315
341
this . applyTrData ( data ) ;
316
342
}
317
343
}
@@ -335,7 +361,10 @@ export class PersistentBottomSheet extends GridLayout {
335
361
}
336
362
set isScrollEnabled ( value : boolean ) {
337
363
if ( this . _isScrollEnabled !== value ) {
338
- this . _isScrollEnabled = this . scrollView . isScrollEnabled = value ;
364
+ this . _isScrollEnabled = value ;
365
+ if ( this . scrollView ) {
366
+ this . scrollView . isScrollEnabled = value ;
367
+ }
339
368
}
340
369
}
341
370
onTouch ( event : TouchGestureEventData ) {
@@ -389,9 +418,10 @@ export class PersistentBottomSheet extends GridLayout {
389
418
// const viewY = this.translationY - height;
390
419
const y = touchY - ( this . lastTouchY || touchY ) ;
391
420
const trY = this . constrainY ( this . translationY + y ) ;
421
+ const height = this . translationMaxOffset ;
392
422
// console.log('constraining on touch event', touchY, this.lastTouchY, y, trY);
393
423
this . translationY = trY ;
394
- const trData = this . computeTranslationData ( ) ;
424
+ const trData = this . computeTranslationData ( height ) ;
395
425
this . applyTrData ( trData ) ;
396
426
}
397
427
this . lastTouchY = touchY ;
@@ -456,15 +486,20 @@ export class PersistentBottomSheet extends GridLayout {
456
486
const y = deltaY - this . prevDeltaY ;
457
487
const trY = this . constrainY ( this . translationY + y ) ;
458
488
this . translationY = trY ;
459
- const trData = this . computeTranslationData ( ) ;
489
+ const height = this . translationMaxOffset ;
490
+ const trData = this . computeTranslationData ( height ) ;
460
491
this . applyTrData ( trData ) ;
461
492
this . prevDeltaY = deltaY ;
462
493
}
463
494
464
495
applyTrData ( trData : { [ k : string ] : any } ) {
465
496
Object . keys ( trData ) . forEach ( ( k ) => {
497
+ const { target, ...others } = trData [ k ] ;
498
+ if ( target ) {
499
+ Object . assign ( target , others ) ;
500
+ }
466
501
if ( this [ k ] ) {
467
- Object . assign ( this [ k ] , trData [ k ] ) ;
502
+ Object . assign ( this [ k ] , others ) ;
468
503
}
469
504
} ) ;
470
505
}
@@ -474,7 +509,6 @@ export class PersistentBottomSheet extends GridLayout {
474
509
}
475
510
476
511
async animateToPosition ( position , duration = OPEN_DURATION ) {
477
- // console.log('animateToPosition', position, new Error().stack);
478
512
if ( this . _scrollView && global . isAndroid ) {
479
513
// on android we get unwanted scroll effect while "swipping the view"
480
514
// cancel the views touches before animation to prevent that
@@ -483,22 +517,32 @@ export class PersistentBottomSheet extends GridLayout {
483
517
event . setAction ( android . view . MotionEvent . ACTION_CANCEL ) ;
484
518
this . scrollView . nativeViewProtected . dispatchTouchEvent ( event ) ;
485
519
}
486
- this . translationY = this . translationMaxOffset - position ;
487
- const trData = this . computeTranslationData ( ) ;
520
+ const height = this . bottomViewHeight ;
521
+ this . translationY = height - position ;
522
+ const trData = this . computeTranslationData ( height ) ;
488
523
489
524
const params = Object . keys ( trData )
490
- . map (
491
- ( k ) =>
492
- this [ k ] &&
493
- Object . assign (
525
+ . map ( ( k ) => {
526
+ const data = trData [ k ] ;
527
+ if ( data . target ) {
528
+ return Object . assign (
529
+ {
530
+ curve : AnimationCurve . easeInOut ,
531
+ duration,
532
+ } ,
533
+ transformAnimationValues ( trData [ k ] )
534
+ ) ;
535
+ } else if ( this [ k ] ) {
536
+ return Object . assign (
494
537
{
495
538
target : this [ k ] ,
496
539
curve : AnimationCurve . easeInOut ,
497
540
duration,
498
541
} ,
499
542
transformAnimationValues ( trData [ k ] )
500
- )
501
- )
543
+ ) ;
544
+ }
545
+ } )
502
546
. filter ( ( a ) => ! ! a ) ;
503
547
try {
504
548
await new Animation ( params ) . play ( ) ;
0 commit comments