@@ -472,21 +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 ( ( ) => {
484- if ( this . leaveAnimationPlayer ) {
485- this . leaveAnimationPlayer . reset ( ) ;
486- }
487- if ( this . enterAnimationPlayer ) {
488- this . enterAnimationPlayer . reset ( ) ;
489- }
486+ this . resetAnimations ( ) ;
490487 this . playAnimations ( ) ;
491488 } ) ;
492489 } else {
@@ -506,15 +503,28 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
506503 this . playEnterAnimation ( ) ;
507504 }
508505
509- private finishAnimations ( ) : boolean {
510- let animationWasStarted = false ;
511- if ( this . previousSlide && this . previousSlide . previous ) {
512- this . previousSlide . previous = false ;
506+ private finishAnimations ( ) {
507+ if ( this . animationStarted ( this . leaveAnimationPlayer ) ) {
508+ this . leaveAnimationPlayer . finish ( ) ;
509+ }
510+
511+ if ( this . animationStarted ( this . enterAnimationPlayer ) ) {
512+ this . enterAnimationPlayer . finish ( ) ;
513+ }
514+ }
515+
516+ private resetAnimations ( ) {
517+ if ( this . animationStarted ( this . leaveAnimationPlayer ) ) {
518+ this . leaveAnimationPlayer . reset ( ) ;
513519 }
514- if ( this . leaveAnimationPlayer || this . enterAnimationPlayer ) {
515- animationWasStarted = true ;
520+
521+ if ( this . animationStarted ( this . enterAnimationPlayer ) ) {
522+ this . enterAnimationPlayer . reset ( ) ;
516523 }
517- return animationWasStarted ;
524+ }
525+
526+ private animationStarted ( animation : AnimationPlayer ) : boolean {
527+ return animation && animation . hasStarted ( ) ;
518528 }
519529
520530 private getAnimation ( ) : CarouselAnimationSettings {
@@ -1024,15 +1034,11 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
10241034 this . stoppedByInteraction = true ;
10251035 this . stop ( ) ;
10261036 }
1027- const animationWasStarted = this . finishAnimations ( ) ;
1028- if ( animationWasStarted ) {
1029- if ( this . leaveAnimationPlayer ) {
1030- this . leaveAnimationPlayer . finish ( ) ;
1031- }
1032- if ( this . enterAnimationPlayer ) {
1033- this . enterAnimationPlayer . finish ( ) ;
1034- }
1037+
1038+ if ( this . previousSlide && this . previousSlide . previous ) {
1039+ this . previousSlide . previous = false ;
10351040 }
1041+ this . finishAnimations ( ) ;
10361042
10371043 if ( this . incomingSlide ) {
10381044 if ( index !== this . incomingSlide . index ) {
0 commit comments