@@ -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,32 @@ export class InnerSlider extends React.Component {
406
406
this . asNavForIndex = index ;
407
407
asNavFor . innerSlider . slideHandler ( index ) ;
408
408
}
409
+
410
+ // Ensure we always fire afterChange callbacks even if we are not
411
+ // animating
412
+ if ( ! waitForAnimate && afterChange ) {
413
+ afterChange ( state . currentSlide ) ;
414
+ }
415
+
409
416
if ( ! nextState ) return ;
417
+
410
418
this . animationEndCallback = setTimeout ( ( ) => {
411
419
const { animating, ...firstBatch } = nextState ;
412
420
this . setState ( firstBatch , ( ) => {
413
421
this . callbackTimers . push (
414
422
setTimeout ( ( ) => this . setState ( { animating } ) , 10 )
415
423
) ;
416
- afterChange && afterChange ( state . currentSlide ) ;
417
424
delete this . animationEndCallback ;
418
425
} ) ;
419
426
} , speed ) ;
427
+
428
+ // Ensure we always fire afterChange callbacks even if animation gets
429
+ // interrupted by a window resize.
430
+ if ( waitForAnimate && afterChange ) {
431
+ this . callbackTimers . push (
432
+ setTimeout ( ( ) => afterChange ( state . currentSlide ) , speed )
433
+ ) ;
434
+ }
420
435
} ) ;
421
436
} ;
422
437
changeSlide = ( options , dontAnimate = false ) => {
0 commit comments