Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #279 from vpishuk/master
Browse files Browse the repository at this point in the history
Issue: slides blinking when going to next slide
  • Loading branch information
Julien Bouquillon committed Dec 26, 2014
2 parents 5a25ac1 + 08ce72f commit 20ec5a2
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/directives/rn-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
animateTransitions = true,
intialState = true,
animating = false,
mouseUpBound = false,
locked = false;

$swipe.bind(iElement, {
Expand Down Expand Up @@ -294,11 +295,13 @@
updateSlidesPosition(state.x);
},
finish: function() {
locked = false;
scope.$apply(function() {
scope.carouselIndex = index;
offset = index * -100;
updateBufferIndex();
$timeout(function () {
locked = false;
}, 0, false);
});
}
});
Expand All @@ -313,12 +316,25 @@
elWidth = getContainerWidth();
}

function bindMouseUpEvent() {
if (!mouseUpBound) {
mouseUpBound = true;
$document.bind('mouseup', documentMouseUpEvent);
}
}

function unbindMouseUpEvent() {
if (mouseUpBound) {
mouseUpBound = false;
$document.unbind('mouseup', documentMouseUpEvent);
}
}

function swipeStart(coords, event) {
// console.log('swipeStart', coords, event);
if (locked || currentSlides.length <= 1) {
return;
}
$document.bind('mouseup', documentMouseUpEvent);
updateContainerWidth();
elX = iElement[0].querySelector('li').getBoundingClientRect().left;
pressed = true;
Expand All @@ -329,6 +345,7 @@
function swipeMove(coords, event) {
//console.log('swipeMove', coords, event);
var x, delta;
bindMouseUpEvent();
if (pressed) {
x = coords.x;
delta = startX - x;
Expand All @@ -351,7 +368,7 @@
currentSlides.push({id: index});
});
}

if (iAttributes.rnCarouselControls!==undefined) {
// dont use a directive for this
var nextSlideIndexCompareValue = isRepeatBased ? repeatCollection.replace('::', '') + '.length - 1' : currentSlides.length - 1;
Expand Down Expand Up @@ -380,10 +397,7 @@
if (angular.isFunction(indexModel.assign)) {
/* check if this property is assignable then watch it */
scope.$watch('carouselIndex', function(newValue) {
if (!locked) {
updateParentIndex(newValue);
}

updateParentIndex(newValue);
});
scope.$parent.$watch(indexModel, function(newValue, oldValue) {

Expand Down Expand Up @@ -453,8 +467,7 @@
if (event && !swipeMoved) {
return;
}

$document.unbind('mouseup', documentMouseUpEvent);
unbindMouseUpEvent();
pressed = false;
swipeMoved = false;
destination = startX - coords.x;
Expand Down Expand Up @@ -493,7 +506,7 @@
}

scope.$on('$destroy', function() {
$document.unbind('mouseup', documentMouseUpEvent);
unbindMouseUpEvent();
});

scope.carouselBufferIndex = 0;
Expand Down Expand Up @@ -540,7 +553,7 @@
winEl.bind('resize', onOrientationChange);

scope.$on('$destroy', function() {
$document.unbind('mouseup', documentMouseUpEvent);
unbindMouseUpEvent();
winEl.unbind('orientationchange', onOrientationChange);
winEl.unbind('resize', onOrientationChange);
});
Expand Down

0 comments on commit 20ec5a2

Please sign in to comment.