|
19 | 19 | */ |
20 | 20 |
|
21 | 21 | document.addEventListener('deviceready', onDeviceReady, false); |
| 22 | + |
22 | 23 | function onDeviceReady() { |
23 | 24 | StatusBar.hide(); |
| 25 | + |
| 26 | + // fix an issue with iOS 12 (@see https://github.com/apache/cordova-ios/issues/417#issuecomment-466520675) |
| 27 | + function ios12NotchFix(is_ios, keyboard_plugin_exists) { |
| 28 | + if (!is_ios || device.model.indexOf("iPhone") === -1) return false; |
| 29 | + if (!keyboard_plugin_exists) throw new Error("This fix depends on 'cordova-plugin-keyboard'!"); |
| 30 | + const iphone_number = Number(device.model.replace("iPhone", "").replace(",", ".")); |
| 31 | + const /* viewport metatag */ |
| 32 | + viewport_el = document.getElementsByName("viewport")[0], |
| 33 | + default_content = "user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"; |
| 34 | + |
| 35 | + if (iphone_number >= 10.6 || iphone_number === 10.3) { /* devices with notch: X, XR, ... */ |
| 36 | + setCover(); |
| 37 | + |
| 38 | + window.addEventListener('keyboardWillShow', setFix); |
| 39 | + window.addEventListener('keyboardWillHide', setCover); |
| 40 | + } |
| 41 | + function setCover() { viewport_el.content = default_content + ", viewport-fit=cover"; } |
| 42 | + function setFix() { viewport_el.content = default_content; } |
| 43 | + } |
| 44 | + |
| 45 | + ios12NotchFix(device.platform === "iOS", typeof Keyboard !== "undefined"); |
24 | 46 | } |
25 | 47 |
|
26 | 48 | document.addEventListener('menubutton', onMenuButton, false); |
|
0 commit comments