From 8be4b1f8ae36d91640290005a5e1d2a2341b674a Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Thu, 1 May 2014 14:05:18 -0500 Subject: [PATCH] Repeat and infinite --- js/animation/animation.js | 32 +++++++++++++++++++++++++------- test/html/animation.html | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/js/animation/animation.js b/js/animation/animation.js index a95612b192..85f757c071 100644 --- a/js/animation/animation.js +++ b/js/animation/animation.js @@ -14,13 +14,15 @@ * The main animation system manager. Treated as a singleton. */ ionic.Animation = { + create: function(opts) { + return new ionic.Animation.Animation(opts); + }, + + /* TODO: Move animation set management here instead of instance anims: [], add: function(animation) { this.anims.push(animation); }, - create: function(opts) { - return new ionic.Animation.Animation(opts); - }, remove: function(animation) { var i, j; for(i = 0, j = this.anims.length; i < j; i++) { @@ -37,13 +39,14 @@ } } }, + */ /** * Stops the given animation. * * @param id {Integer} Unique animation ID * @return {Boolean} Whether the animation was stopped (aka, was running before) - */ + * TODO: Requires above fix stop: function(id) { var cleared = running[id] != null; if (cleared) { @@ -52,6 +55,7 @@ return cleared; }, + */ /** @@ -59,10 +63,10 @@ * * @param id {Integer} Unique animation ID * @return {Boolean} Whether the animation is still running - */ isRunning: function(id) { return running[id] != null; }, + */ }; @@ -144,6 +148,7 @@ var endPercent = isReverse === true ? 0 : 1; var percent = startPercent; var dropCounter = 0; + var iteration = 0; var id = counter++; // Compacting running db automatically every few new animations @@ -205,8 +210,21 @@ // Execute step callback, then... var value = easingMethod ? easingMethod(percent) : percent; if ((stepCallback(value, now, render) === false || percent === endPercent) && render) { - running[id] = null; - completedCallback && completedCallback(desiredFrames - (dropCounter / ((now - start) / millisecondsPerSecond)), id, percent === endPercent || duration == null); + if(repeat === -1) { + start = time(); + percent = startPercent; + lastFrame = now; + ionic.requestAnimationFrame(step); + } else if(iteration < repeat) { + iteration++; + start = time(); + percent = startPercent; + lastFrame = now; + ionic.requestAnimationFrame(step); + } else { + running[id] = null; + completedCallback && completedCallback(desiredFrames - (dropCounter / ((now - start) / millisecondsPerSecond)), id, percent === endPercent || duration == null); + } } else if (render) { lastFrame = now; ionic.requestAnimationFrame(step); diff --git a/test/html/animation.html b/test/html/animation.html index 03926114d0..8c4e982386 100644 --- a/test/html/animation.html +++ b/test/html/animation.html @@ -73,7 +73,7 @@ duration: 500, delay: 0, repeat: -1, - reverse: true, + reverse: false, autoReverse: false } var el = angular.element(document.querySelector('.box'));