Scroll HTML window if necessary when raise keyboard

This commit is contained in:
David Rowe 2016-09-28 19:27:16 +13:00
parent a94d77ee12
commit b60f649e0a
2 changed files with 25 additions and 0 deletions

View file

@ -12,6 +12,7 @@
var MAX_WARNINGS = 3;
var numWarnings = 0;
var isKeyboardRaised = false;
var KEYBOARD_HEIGHT = 200;
function shouldRaiseKeyboard() {
if (document.activeElement.nodeName == "INPUT" || document.activeElement.nodeName == "TEXTAREA") {
@ -31,6 +32,15 @@
setInterval(function () {
if (isKeyboardRaised !== shouldRaiseKeyboard()) {
isKeyboardRaised = !isKeyboardRaised;
if (isKeyboardRaised) {
var delta = document.activeElement.getBoundingClientRect().bottom + 10
- (document.body.clientHeight - KEYBOARD_HEIGHT);
if (delta > 0) {
document.body.scrollTop += delta;
}
}
if (typeof EventBridge != "undefined") {
EventBridge.emitWebEvent(isKeyboardRaised ? "_RAISE_KEYBOARD" : "_LOWER_KEYBOARD");
} else {

View file

@ -11,18 +11,33 @@
function setUpKeyboardControl() {
var lowerTimer = null;
var isRaised = false;
var KEYBOARD_HEIGHT = 200;
function raiseKeyboard() {
if (lowerTimer !== null) {
clearTimeout(lowerTimer);
lowerTimer = null;
}
if (isRaised) {
return;
}
var delta = this.getBoundingClientRect().bottom + 10 - (document.body.clientHeight - KEYBOARD_HEIGHT);
if (delta > 0) {
document.body.scrollTop += delta;
}
EventBridge.emitWebEvent("_RAISE_KEYBOARD");
isRaised = true;
}
function doLowerKeyboard() {
EventBridge.emitWebEvent("_LOWER_KEYBOARD");
lowerTimer = null;
isRaised = false;
}
function lowerKeyboard() {