Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ export class InnerSlider extends React.Component {
beforeChange,
onLazyLoad,
speed,
afterChange
afterChange,
waitForAnimate
} = this.props;
// capture currentslide before state is updated
const currentSlide = this.state.currentSlide;
Expand All @@ -395,9 +396,8 @@ export class InnerSlider extends React.Component {
value => this.state.lazyLoadedList.indexOf(value) < 0
);
onLazyLoad && slidesToLoad.length > 0 && onLazyLoad(slidesToLoad);
if (!this.props.waitForAnimate && this.animationEndCallback) {
if (!waitForAnimate && this.animationEndCallback) {
clearTimeout(this.animationEndCallback);
afterChange && afterChange(currentSlide);
delete this.animationEndCallback;
}
this.setState(state, () => {
Expand All @@ -406,17 +406,32 @@ export class InnerSlider extends React.Component {
this.asNavForIndex = index;
asNavFor.innerSlider.slideHandler(index);
}

// Ensure we always fire afterChange callbacks even if we are not
// animating
if (!waitForAnimate && afterChange) {
afterChange(state.currentSlide);
}

if (!nextState) return;

this.animationEndCallback = setTimeout(() => {
const { animating, ...firstBatch } = nextState;
this.setState(firstBatch, () => {
this.callbackTimers.push(
setTimeout(() => this.setState({ animating }), 10)
);
afterChange && afterChange(state.currentSlide);
delete this.animationEndCallback;
});
}, speed);

// Ensure we always fire afterChange callbacks even if animation gets
// interrupted by a window resize.
if (waitForAnimate && afterChange) {
this.callbackTimers.push(
setTimeout(() => afterChange(state.currentSlide), speed)
);
}
});
};
changeSlide = (options, dontAnimate = false) => {
Expand Down