From c797f2f0ad0216430c606fe82acf01586018ae80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 2 Nov 2013 20:26:06 +0100 Subject: [PATCH] Keep the native animation loop running as long as there are unprocessed callbacks. --- src/dom/DomEvent.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 55d7d865..3d12611e 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -106,7 +106,6 @@ DomEvent.requestAnimationFrame = new function() { }); function handleCallbacks() { - requested = false; // Checks all installed callbacks for element visibility and // execute if needed. for (var i = callbacks.length - 1; i >= 0; i--) { @@ -115,11 +114,22 @@ DomEvent.requestAnimationFrame = new function() { el = entry[1]; if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' || focused) && DomElement.isInView(el)) { - // Handle callback and remove it from callbacks list. + // Only remove from the list once the callback was called. This + // could take a long time based on visibility. But this way we + // are sure to keep the animation loop running. callbacks.splice(i, 1); func(); } } + if (nativeRequest) { + if (callbacks.length) { + // If we haven't processed all callbacks yet, we need to keep + // the loop running, as otherwise it would die off. + nativeRequest(handleCallbacks); + } else { + requested = false; + } + } } return function(callback, element) {