Skip to content

Commit

Permalink
Fixed issue with setting up dimensions and scrolling animated fast. P…
Browse files Browse the repository at this point in the history
…reviously the dimension change has interrupted the previously started scroll animation. Ugh.
  • Loading branch information
Sebastian Werner committed Oct 12, 2011
1 parent 3ecd7d3 commit e101282
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/Scroller.js
Expand Up @@ -264,14 +264,26 @@ var Scroller;
self.__computeScrollMax();

// Respect new boundaries (debounced update)
if (self.__rectDebounce) {
clearTimeout(self.__rectDebounce);
}
// But only do this when there was scrolled before and
// the scroll position has not been modified between
// configuring dimensions and debouncing call.
var oldLeft = self.__scrollLeft;
var oldTop = self.__scrollTop;

if (oldLeft != 0 && oldTop != 0)
{
if (self.__rectDebounce) {
clearTimeout(self.__rectDebounce);
}

self.__rectDebounce = setTimeout(function() {
if (oldLeft == self.__scrollLeft && oldTop == self.__scrollTop && !self.__isAnimating) {
self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
}

self.__rectDebounce = setTimeout(function() {
self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
self.__rectDebounce = null;
}, 100);
self.__rectDebounce = null;
}, 100);
}
},


Expand Down Expand Up @@ -416,7 +428,7 @@ var Scroller;
scrollTo: function(left, top, animate) {

var self = this;

// Stop deceleration
if (self.__isDecelerating) {
zynga.Animate.stop(self.__isDecelerating);
Expand Down Expand Up @@ -460,7 +472,7 @@ var Scroller;
if (left === self.__scrollLeft && top === self.__scrollTop) {
animate = false;
}

// Publish new values
self.__publish(left, top, self.__zoomLevel, animate);

Expand Down Expand Up @@ -788,7 +800,7 @@ var Scroller;
__publish: function(left, top, zoom, animate) {

var self = this;

// Remember whether we had an animation, then we try to continue based on the current "drive" of the animation
var wasAnimating = self.__isAnimating;
if (wasAnimating) {
Expand Down Expand Up @@ -830,8 +842,6 @@ var Scroller;
};

var completed = function(renderedFramesPerSecond, animationId, wasFinished) {
// console.debug("Rendered FPS: " + renderedFramesPerSecond);

if (animationId === self.__isAnimating) {
self.__isAnimating = false;
}
Expand Down Expand Up @@ -923,8 +933,6 @@ var Scroller;
};

var completed = function(renderedFramesPerSecond, animationId, wasFinished) {
// console.debug("Rendered FPS: " + renderedFramesPerSecond);

self.__isDecelerating = false;

// Animate to grid when snapping is active, otherwise just fix out-of-boundary positions
Expand Down

0 comments on commit e101282

Please sign in to comment.