@@ -437,7 +437,7 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
437437 private newDuration = 0 ;
438438
439439 constructor ( private element : ElementRef , private iterableDiffers : IterableDiffers ,
440- private builder : AnimationBuilder , private platformUtil : PlatformUtil ) {
440+ private builder : AnimationBuilder , private platformUtil : PlatformUtil ) {
441441 this . differ = this . iterableDiffers . find ( [ ] ) . create ( null ) ;
442442 }
443443
@@ -472,15 +472,18 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
472472 }
473473
474474 if ( this . currentSlide ) {
475- const animationWasStarted = this . finishAnimations ( ) ;
475+ if ( this . previousSlide && this . previousSlide . previous ) {
476+ this . previousSlide . previous = false ;
477+ }
476478 this . currentSlide . direction = slide . direction ;
477479 this . currentSlide . active = false ;
478480
479481 this . previousSlide = this . currentSlide ;
480482 this . currentSlide = slide ;
481483 if ( this . animationType !== CarouselAnimationType . none ) {
482- if ( animationWasStarted ) {
484+ if ( this . animationStarted ( this . leaveAnimationPlayer ) || this . animationStarted ( this . enterAnimationPlayer ) ) {
483485 requestAnimationFrame ( ( ) => {
486+ this . resetAnimations ( ) ;
484487 this . playAnimations ( ) ;
485488 } ) ;
486489 } else {
@@ -500,20 +503,28 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
500503 this . playEnterAnimation ( ) ;
501504 }
502505
503- private finishAnimations ( ) : boolean {
504- let animationWasStarted = false ;
505- if ( this . previousSlide && this . previousSlide . previous ) {
506- this . previousSlide . previous = false ;
507- }
508- if ( this . leaveAnimationPlayer ) {
509- animationWasStarted = true ;
506+ private finishAnimations ( ) {
507+ if ( this . animationStarted ( this . leaveAnimationPlayer ) ) {
510508 this . leaveAnimationPlayer . finish ( ) ;
511509 }
512- if ( this . enterAnimationPlayer ) {
513- animationWasStarted = true ;
510+
511+ if ( this . animationStarted ( this . enterAnimationPlayer ) ) {
514512 this . enterAnimationPlayer . finish ( ) ;
515513 }
516- return animationWasStarted ;
514+ }
515+
516+ private resetAnimations ( ) {
517+ if ( this . animationStarted ( this . leaveAnimationPlayer ) ) {
518+ this . leaveAnimationPlayer . reset ( ) ;
519+ }
520+
521+ if ( this . animationStarted ( this . enterAnimationPlayer ) ) {
522+ this . enterAnimationPlayer . reset ( ) ;
523+ }
524+ }
525+
526+ private animationStarted ( animation : AnimationPlayer ) : boolean {
527+ return animation && animation . hasStarted ( ) ;
517528 }
518529
519530 private getAnimation ( ) : CarouselAnimationSettings {
@@ -565,10 +576,11 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
565576 }
566577
567578 private playEnterAnimation ( ) {
568- if ( ! this . getAnimation ( ) . enterAnimation ) {
579+ const animation = this . getAnimation ( ) . enterAnimation ;
580+ if ( ! animation ) {
569581 return ;
570582 }
571- const animationBuilder = this . builder . build ( this . getAnimation ( ) . enterAnimation ) ;
583+ const animationBuilder = this . builder . build ( animation ) ;
572584
573585 this . enterAnimationPlayer = animationBuilder . create ( this . currentSlide . nativeElement ) ;
574586
@@ -586,11 +598,12 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
586598 }
587599
588600 private playLeaveAnimation ( ) {
589- if ( ! this . getAnimation ( ) . leaveAnimation ) {
601+ const animation = this . getAnimation ( ) . leaveAnimation ;
602+ if ( ! animation ) {
590603 return ;
591604 }
592605
593- const animationBuilder = this . builder . build ( this . getAnimation ( ) . leaveAnimation ) ;
606+ const animationBuilder = this . builder . build ( animation ) ;
594607 this . leaveAnimationPlayer = animationBuilder . create ( this . previousSlide . nativeElement ) ;
595608
596609 this . leaveAnimationPlayer . onDone ( ( ) => {
@@ -1021,6 +1034,10 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
10211034 this . stoppedByInteraction = true ;
10221035 this . stop ( ) ;
10231036 }
1037+
1038+ if ( this . previousSlide && this . previousSlide . previous ) {
1039+ this . previousSlide . previous = false ;
1040+ }
10241041 this . finishAnimations ( ) ;
10251042
10261043 if ( this . incomingSlide ) {
0 commit comments