mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
re-center focused eleemnt even if keyboard was already visible
This commit is contained in:
parent
00c3dcee2f
commit
1021aa1a0e
1 changed files with 21 additions and 9 deletions
|
@ -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;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue