@@ -186,16 +186,17 @@ import { GestureController } from '../../gestures/gesture-controller';
186
186
encapsulation : ViewEncapsulation . None ,
187
187
} )
188
188
export class Menu {
189
- private _preventTime : number = 0 ;
190
189
private _cntEle : HTMLElement ;
191
190
private _cntGesture : MenuContentGesture ;
192
191
private _type : MenuType ;
193
192
private _resizeUnreg : Function ;
194
193
private _isEnabled : boolean = true ;
195
194
private _isSwipeEnabled : boolean = true ;
195
+ private _isAnimating : boolean = false ;
196
196
private _isPers : boolean = false ;
197
197
private _init : boolean = false ;
198
198
199
+
199
200
/**
200
201
* @private
201
202
*/
@@ -378,21 +379,20 @@ export class Menu {
378
379
* @private
379
380
*/
380
381
private _setListeners ( ) {
381
- let self = this ;
382
-
383
- if ( self . _init ) {
384
- // only listen/unlisten if the menu has initialized
382
+ if ( ! this . _init ) {
383
+ return ;
384
+ }
385
385
386
- if ( self . _isEnabled && self . _isSwipeEnabled && ! self . _cntGesture . isListening ) {
387
- // should listen, but is not currently listening
388
- console . debug ( 'menu, gesture listen' , self . side ) ;
389
- self . _cntGesture . listen ( ) ;
386
+ // only listen/unlisten if the menu has initialized
387
+ if ( this . _isEnabled && this . _isSwipeEnabled && ! this . _cntGesture . isListening ) {
388
+ // should listen, but is not currently listening
389
+ console . debug ( 'menu, gesture listen' , this . side ) ;
390
+ this . _cntGesture . listen ( ) ;
390
391
391
- } else if ( self . _cntGesture . isListening && ( ! self . _isEnabled || ! self . _isSwipeEnabled ) ) {
392
- // should not listen, but is currently listening
393
- console . debug ( 'menu, gesture unlisten' , self . side ) ;
394
- self . _cntGesture . unlisten ( ) ;
395
- }
392
+ } else if ( this . _cntGesture . isListening && ( ! this . _isEnabled || ! this . _isSwipeEnabled ) ) {
393
+ // should not listen, but is currently listening
394
+ console . debug ( 'menu, gesture unlisten' , this . side ) ;
395
+ this . _cntGesture . unlisten ( ) ;
396
396
}
397
397
}
398
398
@@ -416,7 +416,7 @@ export class Menu {
416
416
setOpen ( shouldOpen : boolean , animated : boolean = true ) : Promise < boolean > {
417
417
// _isPrevented is used to prevent unwanted opening/closing after swiping open/close
418
418
// or swiping open the menu while pressing down on the MenuToggle button
419
- if ( ( shouldOpen && this . isOpen ) || this . _isPrevented ( ) ) {
419
+ if ( ( shouldOpen && this . isOpen ) || ! this . _isEnabled || this . _isAnimating ) {
420
420
return Promise . resolve ( this . isOpen ) ;
421
421
}
422
422
@@ -430,12 +430,20 @@ export class Menu {
430
430
} ) ;
431
431
}
432
432
433
+
434
+ /**
435
+ * @private
436
+ */
437
+ canSwipe ( ) : boolean {
438
+ return this . _isEnabled && this . _isSwipeEnabled && ! this . _isAnimating ;
439
+ }
440
+
433
441
/**
434
442
* @private
435
443
*/
436
444
swipeStart ( ) {
437
445
// user started swiping the menu open/close
438
- if ( this . _isEnabled && this . _isSwipeEnabled && ! this . _isPrevented ( ) ) {
446
+ if ( this . canSwipe ( ) ) {
439
447
this . _before ( ) ;
440
448
this . _getType ( ) . setProgressStart ( this . isOpen ) ;
441
449
}
@@ -446,84 +454,67 @@ export class Menu {
446
454
*/
447
455
swipeProgress ( stepValue : number ) {
448
456
// user actively dragging the menu
449
- if ( this . _isEnabled && this . _isSwipeEnabled ) {
450
- this . _prevent ( ) ;
451
- this . _getType ( ) . setProgessStep ( stepValue ) ;
452
- this . ionDrag . emit ( stepValue ) ;
457
+ if ( ! this . _isAnimating ) {
458
+ return ;
453
459
}
460
+ this . _getType ( ) . setProgessStep ( stepValue ) ;
461
+ this . ionDrag . emit ( stepValue ) ;
454
462
}
455
463
456
464
/**
457
465
* @private
458
466
*/
459
467
swipeEnd ( shouldCompleteLeft : boolean , shouldCompleteRight : boolean , stepValue : number ) {
468
+ if ( ! this . _isAnimating ) {
469
+ return ;
470
+ }
460
471
// user has finished dragging the menu
461
- if ( this . _isEnabled && this . _isSwipeEnabled ) {
462
- this . _prevent ( ) ;
463
-
464
- let opening = ! this . isOpen ;
465
- let shouldComplete = false ;
466
- if ( opening ) {
467
- shouldComplete = ( this . side === 'right' ) ? shouldCompleteLeft : shouldCompleteRight ;
468
- } else {
469
- shouldComplete = ( this . side === 'right' ) ? shouldCompleteRight : shouldCompleteLeft ;
470
- }
471
-
472
- this . _getType ( ) . setProgressEnd ( shouldComplete , stepValue , ( isOpen : boolean ) => {
473
- console . debug ( 'menu, swipeEnd' , this . side ) ;
474
- this . _after ( isOpen ) ;
475
- } ) ;
472
+ let opening = ! this . isOpen ;
473
+ let shouldComplete = false ;
474
+ if ( opening ) {
475
+ shouldComplete = ( this . side === 'right' ) ? shouldCompleteLeft : shouldCompleteRight ;
476
+ } else {
477
+ shouldComplete = ( this . side === 'right' ) ? shouldCompleteRight : shouldCompleteLeft ;
476
478
}
479
+
480
+ this . _getType ( ) . setProgressEnd ( shouldComplete , stepValue , ( isOpen : boolean ) => {
481
+ console . debug ( 'menu, swipeEnd' , this . side ) ;
482
+ this . _after ( isOpen ) ;
483
+ } ) ;
477
484
}
478
485
479
486
private _before ( ) {
480
487
// this places the menu into the correct location before it animates in
481
488
// this css class doesn't actually kick off any animations
482
- if ( this . _isEnabled ) {
483
- this . getNativeElement ( ) . classList . add ( 'show-menu' ) ;
484
- this . getBackdropElement ( ) . classList . add ( 'show-backdrop' ) ;
485
-
486
- this . _prevent ( ) ;
487
- this . _keyboard . close ( ) ;
488
- }
489
+ this . getNativeElement ( ) . classList . add ( 'show-menu' ) ;
490
+ this . getBackdropElement ( ) . classList . add ( 'show-backdrop' ) ;
491
+ this . _keyboard . close ( ) ;
492
+ this . _isAnimating = true ;
489
493
}
490
494
491
495
private _after ( isOpen : boolean ) {
492
496
// keep opening/closing the menu disabled for a touch more yet
493
497
// only add listeners/css if it's enabled and isOpen
494
498
// and only remove listeners/css if it's not open
495
499
// emit opened/closed events
496
- if ( ( this . _isEnabled && isOpen ) || ! isOpen ) {
497
- this . _prevent ( ) ;
498
-
499
- this . isOpen = isOpen ;
500
+ this . isOpen = isOpen ;
501
+ this . _isAnimating = false ;
500
502
501
- ( < any > this . _cntEle . classList ) [ isOpen ? 'add' : 'remove' ] ( 'menu-content-open' ) ;
503
+ ( < any > this . _cntEle . classList ) [ isOpen ? 'add' : 'remove' ] ( 'menu-content-open' ) ;
502
504
503
- this . _cntEle . removeEventListener ( 'click' , this . onContentClick ) ;
505
+ this . _cntEle . removeEventListener ( 'click' , this . onContentClick ) ;
504
506
505
- if ( isOpen ) {
506
- this . _cntEle . addEventListener ( 'click' , this . onContentClick ) ;
507
- this . ionOpen . emit ( true ) ;
507
+ if ( isOpen ) {
508
+ this . _cntEle . addEventListener ( 'click' , this . onContentClick ) ;
509
+ this . ionOpen . emit ( true ) ;
508
510
509
- } else {
510
- this . getNativeElement ( ) . classList . remove ( 'show-menu' ) ;
511
- this . getBackdropElement ( ) . classList . remove ( 'show-backdrop' ) ;
512
- this . ionClose . emit ( true ) ;
513
- }
511
+ } else {
512
+ this . getNativeElement ( ) . classList . remove ( 'show-menu' ) ;
513
+ this . getBackdropElement ( ) . classList . remove ( 'show-backdrop' ) ;
514
+ this . ionClose . emit ( true ) ;
514
515
}
515
516
}
516
517
517
- private _prevent ( ) {
518
- // used to prevent unwanted opening/closing after swiping open/close
519
- // or swiping open the menu while pressing down on the MenuToggle
520
- this . _preventTime = Date . now ( ) + 20 ;
521
- }
522
-
523
- private _isPrevented ( ) {
524
- return this . _preventTime > Date . now ( ) ;
525
- }
526
-
527
518
/**
528
519
* @private
529
520
*/
@@ -564,6 +555,9 @@ export class Menu {
564
555
. map ( m => m . enabled = false ) ;
565
556
}
566
557
558
+ // TODO
559
+ // what happens if menu is disabled while swipping?
560
+
567
561
return this ;
568
562
}
569
563
@@ -572,6 +566,8 @@ export class Menu {
572
566
*/
573
567
swipeEnable ( shouldEnable : boolean ) : Menu {
574
568
this . swipeEnabled = shouldEnable ;
569
+ // TODO
570
+ // what happens if menu swipe is disabled while swipping?
575
571
return this ;
576
572
}
577
573
@@ -619,7 +615,11 @@ export class Menu {
619
615
this . _cntGesture && this . _cntGesture . destroy ( ) ;
620
616
this . _type && this . _type . destroy ( ) ;
621
617
this . _resizeUnreg && this . _resizeUnreg ( ) ;
618
+
619
+ this . _cntGesture = null ;
620
+ this . _type = null ;
622
621
this . _cntEle = null ;
622
+ this . _resizeUnreg = null ;
623
623
}
624
624
625
625
}
0 commit comments