From bd70a73d43ce71faff424bb692e339f55f335713 Mon Sep 17 00:00:00 2001 From: Travis Grathwell Date: Fri, 31 Mar 2017 15:31:04 -0700 Subject: [PATCH] ios: Patch cancelAnimationFrame whenever fakeRequestAnimationFrame is used The existing implementation of fakeRequestAnimationFrame did not return a timer ID, so the frame could not be cancelled if you wanted to cancel it. But if you do want to cancel it, it needs to be cancelled through clearTimeout instead of cancelAnimationFrame, because the timer IDs are different. Signed-off-by: Jonathan Barnes --- src/shared/compatibility.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 3f727a5c3..90e1165af 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -643,8 +643,13 @@ PDFJS.compatibilityChecked = true; // Support: IE<10, Android<4.0, iOS (function checkRequestAnimationFrame() { - function fakeRequestAnimationFrame(callback) { - window.setTimeout(callback, 20); + function installFakeAnimationFrameFunctions() { + window.requestAnimationFrame = function (callback) { + return window.setTimeout(callback, 20); + }; + window.cancelAnimationFrame = function (timeoutID) { + window.clearTimeout(timeoutID); + }; } if (!hasDOM) { @@ -652,7 +657,7 @@ PDFJS.compatibilityChecked = true; } if (isIOS) { // requestAnimationFrame on iOS is broken, replacing with fake one. - window.requestAnimationFrame = fakeRequestAnimationFrame; + installFakeAnimationFrameFunctions(); return; } if ('requestAnimationFrame' in window) { @@ -660,8 +665,10 @@ PDFJS.compatibilityChecked = true; } window.requestAnimationFrame = window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - fakeRequestAnimationFrame; + window.webkitRequestAnimationFrame; + if (!('requestAnimationFrame' in window)) { + installFakeAnimationFrameFunctions(); + } })(); // Support: Android, iOS