Keyboard Issue of Hybrid Web App on Android and iOS- 1 min
Hybrid Apps has many advantages, but it also brings some headaches when it comes to integratation with native components, such as camera, keyboard, form etc. I encountered a typical issue where the form is blocked by the activated keyboard. Apart from solutions from libraries or frameworks like ionic, other options including iScroll, css position, and of course tweaks in native android code. Below is a snippet works fine on iOS (you can scroll the form at least), but it just couldn’t work on Android, what’s more weird is that it actually could work occasionally, which made the process of debug not easy.
Fortunately, this can be solved by updating Android settings:
- In AndroidManifest.xml file, add
android:screenOrientation="portrait"for each view;
- Add meta tag
"height=device-height"in your html file, in my case, it is
<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0, initial-scale=1.0, height=device-height"/>.
I just ran into a similar issue on iOS, specifically iOS 8.3. The odd thing is that
next.focus() works on older version such as iOS 8.1. As always, I tried to solve the ‘auto focus’ effect issue within the domain of web area. However, ‘focusin’ event is more bizzare on iOS as described here. As far as I can tell, at this point, the best solution is to update the iOS configure - keyboardDisplayRequiresUserAction. Per the API document: ‘When set to NO, a focus event on an element causes the input view to be displayed and associated with that element automatically’.