Skip to content

Commit

Permalink
fix(module): fix issue with snapToPrev() and snapToNext() when us…
Browse files Browse the repository at this point in the history
…ed in conjunction with debounced callback
  • Loading branch information
bd-arc committed Jun 11, 2017
1 parent 7efa350 commit ab3f3b7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default class Carousel extends Component {
interpolators: []
};
this._positions = [];
this._isComingBack = false;
this._canExecuteCallback = props.onSnapToItem !== undefined;
this._initInterpolators = this._initInterpolators.bind(this);
this._onScroll = this._onScroll.bind(this);
Expand Down Expand Up @@ -393,7 +394,15 @@ export default class Carousel extends Component {
}

if (activeItem !== newActiveItem) {
// Prevent issues with `snapToPrev()` on the first slide and `snapToNext()` on the last one
// since intermediate slides would otherwise be set as active items
// With debounced callback, inactive animation would then be ignored
if (this._isComingBack && newActiveItem !== 0 && newActiveItem !== this._positions.length - 1) {
return;
}

this.setState({ activeItem: newActiveItem });
this._isComingBack = false;

if (!enableMomentum) {
this._onSnapToItemDebounced(newActiveItem);
Expand Down Expand Up @@ -628,6 +637,7 @@ export default class Carousel extends Component {
let newIndex = this.currentIndex + 1;
if (newIndex > itemsLength - 1) {
newIndex = 0;
this._isComingBack = true;
}
this.snapToItem(newIndex, animated);
}
Expand All @@ -638,6 +648,7 @@ export default class Carousel extends Component {
let newIndex = this.currentIndex - 1;
if (newIndex < 0) {
newIndex = itemsLength - 1;
this._isComingBack = true;
}
this.snapToItem(newIndex, animated);
}
Expand Down

0 comments on commit ab3f3b7

Please sign in to comment.