@@ -378,7 +378,8 @@ export class InnerSlider extends React.Component {
378
378
beforeChange,
379
379
onLazyLoad,
380
380
speed,
381
- afterChange
381
+ afterChange,
382
+ waitForAnimate
382
383
} = this . props ;
383
384
// capture currentslide before state is updated
384
385
const currentSlide = this . state . currentSlide ;
@@ -395,9 +396,8 @@ export class InnerSlider extends React.Component {
395
396
value => this . state . lazyLoadedList . indexOf ( value ) < 0
396
397
) ;
397
398
onLazyLoad && slidesToLoad . length > 0 && onLazyLoad ( slidesToLoad ) ;
398
- if ( ! this . props . waitForAnimate && this . animationEndCallback ) {
399
+ if ( ! waitForAnimate && this . animationEndCallback ) {
399
400
clearTimeout ( this . animationEndCallback ) ;
400
- afterChange && afterChange ( currentSlide ) ;
401
401
delete this . animationEndCallback ;
402
402
}
403
403
this . setState ( state , ( ) => {
@@ -406,17 +406,30 @@ export class InnerSlider extends React.Component {
406
406
this . asNavForIndex = index ;
407
407
asNavFor . innerSlider . slideHandler ( index ) ;
408
408
}
409
+
410
+ if ( ! waitForAnimate && afterChange ) {
411
+ afterChange ( state . currentSlide ) ;
412
+ }
413
+
409
414
if ( ! nextState ) return ;
415
+
410
416
this . animationEndCallback = setTimeout ( ( ) => {
411
417
const { animating, ...firstBatch } = nextState ;
412
418
this . setState ( firstBatch , ( ) => {
413
419
this . callbackTimers . push (
414
420
setTimeout ( ( ) => this . setState ( { animating } ) , 10 )
415
421
) ;
416
- afterChange && afterChange ( state . currentSlide ) ;
417
422
delete this . animationEndCallback ;
418
423
} ) ;
419
424
} , speed ) ;
425
+
426
+ // Ensure we always fire afterChange callbacks even if we are not
427
+ // animating or if the animation gets interrupted by a window resize.
428
+ if ( waitForAnimate && afterChange ) {
429
+ this . callbackTimers . push (
430
+ setTimeout ( ( ) => afterChange ( state . currentSlide ) , speed )
431
+ ) ;
432
+ }
420
433
} ) ;
421
434
} ;
422
435
changeSlide = ( options , dontAnimate = false ) => {
0 commit comments