From a311dd06fee9c00926cb8598166edfb50ea93b21 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Sep 2017 16:50:04 +1000 Subject: [PATCH] UX: mess with iPad and iPhone sizing to compensate for keyboard iOS still has no mechanism for figuring out how big the keyboard is, so we fudge it. --- .../discourse/lib/safari-hacks.js.es6 | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 index a7d715ab8b1..aa223617bea 100644 --- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 +++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 @@ -6,17 +6,38 @@ export function isAppleDevice() { !navigator.userAgent.match(/Trident/g); } - // we can't tell what the actual visible window height is // because we cannot account for the height of the mobile keyboard // and any other mobile autocomplete UI that may appear // so let's be conservative here rather than trying to max out every // available pixel of height for the editor -function calcHeight(composingTopic) { - const winHeight = window.innerHeight; - const ratio = composingTopic ? 0.45 : 0.45; - const min = composingTopic ? 300 : 300; - return Math.max(parseInt(winHeight*ratio), min); +function calcHeight() { + + // estimate 270 px for keyboard + let withoutKeyboard = window.innerHeight - 270; + const min = 270; + + // iPhone 6/7/8 + if (window.innerHeight === 553) { + withoutKeyboard = 308; + } + + // iPhone 6/7/8 plus + if (window.innerHeight === 622) { + withoutKeyboard = 360; + } + + // iPad landscape, so we have a bigger keyboard + if (window.innerWidth > window.innerHeight && window.innerHeight > 690) { + withoutKeyboard -= 128; + } + + // iPad portrait also has a bigger keyboard + if (window.innerWidth < window.innerHeight && window.innerHeight > 950) { + withoutKeyboard -= 45; + } + + return Math.max(withoutKeyboard, min); } let workaroundActive = false;