From 00c3dcee2fc2059320d7e89d526c1d809b6c7f15 Mon Sep 17 00:00:00 2001 From: beholder Date: Thu, 28 Sep 2017 00:28:54 +0300 Subject: [PATCH 1/3] 7925 Create Mode: keyboard focused entry field is not visible note: changed the way of calculation scroll value after showing virtual keyboard. Now it doesn't require KEYBOARD_HEGHT and will always try to position focused element at vertical center of the client area --- .../resources/html/raiseAndLowerKeyboard.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index 27ead23124..f87312b838 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -14,7 +14,6 @@ var isWindowFocused = true; var isKeyboardRaised = false; var isNumericKeyboard = false; - var KEYBOARD_HEIGHT = 200; function shouldRaiseKeyboard() { var nodeName = document.activeElement.nodeName; @@ -56,13 +55,15 @@ } if (!isKeyboardRaised) { - var delta = document.activeElement.getBoundingClientRect().bottom + 10 - - (document.body.clientHeight - KEYBOARD_HEIGHT); - if (delta > 0) { - setTimeout(function () { - document.body.scrollTop += delta; - }, 500); // Allow time for keyboard to be raised in QML. - } + var timeout = setTimeout(function () { + clearTimeout(timeout); + + var elementRect = document.activeElement.getBoundingClientRect(); + var absoluteElementTop = elementRect.top + window.scrollY; + var middle = absoluteElementTop - (window.innerHeight / 2); + + window.scrollTo(0, middle); + }, 500); // Allow time for keyboard to be raised in QML. } isKeyboardRaised = keyboardRaised; From 1021aa1a0efaa46508781d7df0632b1f76007fb8 Mon Sep 17 00:00:00 2001 From: beholder Date: Thu, 28 Sep 2017 12:53:10 +0300 Subject: [PATCH 2/3] re-center focused eleemnt even if keyboard was already visible --- .../resources/html/raiseAndLowerKeyboard.js | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index f87312b838..bbf88ca277 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -37,6 +37,19 @@ return document.activeElement.type === "number"; }; + function scheduleBringToView(timeout) { + + var timer = setTimeout(function () { + clearTimeout(timer); + + var elementRect = document.activeElement.getBoundingClientRect(); + var absoluteElementTop = elementRect.top + window.scrollY; + var middle = absoluteElementTop - (window.innerHeight / 2); + + window.scrollTo(0, middle); + }, timeout); + } + setInterval(function () { var keyboardRaised = shouldRaiseKeyboard(); var numericKeyboard = shouldSetNumeric(); @@ -55,15 +68,7 @@ } if (!isKeyboardRaised) { - var timeout = setTimeout(function () { - clearTimeout(timeout); - - var elementRect = document.activeElement.getBoundingClientRect(); - var absoluteElementTop = elementRect.top + window.scrollY; - var middle = absoluteElementTop - (window.innerHeight / 2); - - window.scrollTo(0, middle); - }, 500); // Allow time for keyboard to be raised in QML. + scheduleBringToView(500); // Allow time for keyboard to be raised in QML. } isKeyboardRaised = keyboardRaised; @@ -71,6 +76,13 @@ } }, POLL_FREQUENCY); + window.addEventListener("click", function () { + var keyboardRaised = shouldRaiseKeyboard(); + if(keyboardRaised && isKeyboardRaised) { + scheduleBringToView(150); + } + }); + window.addEventListener("focus", function () { isWindowFocused = true; }); From 338a230de970010fa28f4c98d4b4c934af324435 Mon Sep 17 00:00:00 2001 From: beholder Date: Thu, 28 Sep 2017 13:01:07 +0300 Subject: [PATCH 3/3] reduced delay to improve user experience --- interface/resources/html/raiseAndLowerKeyboard.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index bbf88ca277..ad1d889556 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -68,7 +68,8 @@ } if (!isKeyboardRaised) { - scheduleBringToView(500); // Allow time for keyboard to be raised in QML. + scheduleBringToView(250); // Allow time for keyboard to be raised in QML. + // 2DO: should it be rather done from 'client area height changed' event? } isKeyboardRaised = keyboardRaised;