From 0ed92a4b334d327e14b995a0485ef71a0c7c908f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Thu, 13 Jun 2019 11:19:19 +0200 Subject: [PATCH 1/2] Disable snapping when scroll mode is enabled --- r2-streamer-swift/Resources/scripts/utils.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/r2-streamer-swift/Resources/scripts/utils.js b/r2-streamer-swift/Resources/scripts/utils.js index 58345291..aea57d43 100644 --- a/r2-streamer-swift/Resources/scripts/utils.js +++ b/r2-streamer-swift/Resources/scripts/utils.js @@ -8,7 +8,10 @@ var readium = (function() { window.addEventListener("load", function(){ // on page load // Notify native code that the page is loaded. webkit.messageHandlers.didLoad.postMessage(""); - window.addEventListener("orientationchange", orientationChanged); + window.addEventListener("orientationchange", function() { + orientationChanged(); + snapCurrentPosition(); + }); orientationChanged(); }, false); @@ -37,7 +40,6 @@ var readium = (function() { function orientationChanged() { maxScreenX = (window.orientation === 0 || window.orientation == 180) ? screen.width : screen.height; - snapCurrentPosition(); } function isScrollModeEnabled() { @@ -122,6 +124,9 @@ var readium = (function() { } function snapCurrentPosition() { + if (isScrollModeEnabled()) { + return; + } var currentOffset = window.scrollX; var currentOffsetSnapped = snapOffset(currentOffset + 1); From 4d1fb8bf825d8cfc8afc5f723da3a8db3bb5a372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Fri, 14 Jun 2019 17:17:23 +0200 Subject: [PATCH 2/2] Fix timing when emitting the EPUB didLoad event --- r2-streamer-swift/Resources/scripts/utils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/r2-streamer-swift/Resources/scripts/utils.js b/r2-streamer-swift/Resources/scripts/utils.js index aea57d43..d533311d 100644 --- a/r2-streamer-swift/Resources/scripts/utils.js +++ b/r2-streamer-swift/Resources/scripts/utils.js @@ -6,13 +6,16 @@ var readium = (function() { // Notify native code that the page has loaded. window.addEventListener("load", function(){ // on page load - // Notify native code that the page is loaded. - webkit.messageHandlers.didLoad.postMessage(""); window.addEventListener("orientationchange", function() { orientationChanged(); snapCurrentPosition(); }); orientationChanged(); + + // Notify native code that the page is loaded after the page is rendered. + window.requestAnimationFrame(function() { + webkit.messageHandlers.didLoad.postMessage(""); + }); }, false); var last_known_scrollX_position = 0;