if I click on empty space somewhere near an input or button (within approximately 20px radius) the keyboard will open but the input will not gain focus. If I type anything with the keyboard nothing really happens, I only see text suggestions at the top.
Moreover, if the keyboard is already open and I do the same thing, it closes as usual but re-opens immediately after that.
Even worse, if I double click instead the whole app will crash, with stack trace going somewhere deep inside UIKit and ObjC runtime (crash happens in objc_msgSend).
This basically happens on every screen where I have text fields.
window.addEventListener('native.keyboardshow', keyboardShowHandler)
function keyboardShowHandler (e) {
// prevent a bug where click near input causes keyboard to pop up but input is not focused
if (document.activeElement === document.body) {
window.cordova.plugins.Keyboard.close()
}
}
I was actually very surprised that this fixed it. I was expecting that the keyboard would open (or at least start opening), and then close again after the javascript detected that an input element was not focused. But it actually prevented the keyboard from coming up entirely.
Here is a similar alternate solution which also worked for me.
var activeElement = document.activeElement
if (activeElement.nodeName !== 'INPUT' && activeElement.nodeName !== 'TEXTAREA') {
window.cordova.plugins.Keyboard.close()
}