Skip to content

Commit

Permalink
prevent unexpected page resizing on Android/iOS when soft keyboard ap…
Browse files Browse the repository at this point in the history
…pears or tab/address bar auto-hide occurs
  • Loading branch information
MurakamiShinyu committed Oct 30, 2018
1 parent 5e66a60 commit 00f2be4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/adapt/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,16 @@ adapt.viewer.Viewer.prototype.sizeIsGood = function() {
if (!spreadViewChanged && viewport.width == this.viewport.width && viewport.height == this.viewport.height) {
return true;
}

if (!spreadViewChanged && viewport.width == this.viewport.width &&
viewport.height != this.viewport.height &&
(/Android|iPhone|iPad|iPod/).test(navigator.userAgent)) {
// On mobile browsers, the viewport height may change unexpectedly
// when soft keyboard appears or tab/address bar auto-hide occurs,
// so ignore resizing in this condition.
return true;
}

if (this.opfView && this.opfView.hasPages() && !this.opfView.hasAutoSizedPages()) {
this.viewport.width = viewport.width;
this.viewport.height = viewport.height;
Expand Down Expand Up @@ -808,11 +818,6 @@ adapt.viewer.Viewer.prototype.cancelRenderingTask = function() {
adapt.viewer.Viewer.prototype.resize = function() {
this.needResize = false;
this.needRefresh = false;
if (document.activeElement && document.activeElement.tagName.toLowerCase() === "input" &&
(/Android/).test(navigator.userAgent)) {
// prevent resizing when soft keyboard appears on Android
return adapt.task.newResult(true);
}
if (this.sizeIsGood()) {
return adapt.task.newResult(true);
}
Expand Down

0 comments on commit 00f2be4

Please sign in to comment.