FIX: Mobile Safari composer improvements (#8069)

FIX: Mobile Safari composer improvements (#8069)

  • prevents keyboard from being invoked when textarea is disabled

  • avoids scrolling up when switching focus from title to textarea on new topic creation

diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
index fa619da..1c23463 100644
--- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
+++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6
@@ -63,7 +63,6 @@ function calcHeight() {
 }
 
 let workaroundActive = false;
-let composingTopic = false;
 
 export function isWorkaroundActive() {
   return workaroundActive;
@@ -129,11 +128,24 @@ function positioningWorkaround($fixedElement) {
     if (fixedElement.style.top === "0px") {
       if (this !== document.activeElement) {
         evt.preventDefault();
+
+        // this tricks safari into assuming current input is at top of the viewport
+        // via https://stackoverflow.com/questions/38017771/mobile-safari-prevent-scroll-page-when-focus-on-input
+        this.style.transform = "translateY(-200px)";
         this.focus();
+        let _this = this;
+        setTimeout(function() {
+          _this.style.transform = "none";
+        }, 50);
       }
       return;
     }
 
+    // don't trigger keyboard on disabled element (happens when a category is required)
+    if (this.disabled) {
+      return;
+    }
+
     originalScrollTop = $(window).scrollTop();
 
     // take care of body
@@ -153,9 +165,7 @@ function positioningWorkaround($fixedElement) {
 
     fixedElement.style.top = "0px";
 
-    composingTopic = $("#reply-control .category-chooser").length > 0;
-
-    const height = calcHeight(composingTopic);
+    const height = calcHeight();
     fixedElement.style.height = height + "px";
 
     $(fixedElement).addClass("no-transition");

GitHub sha: 21e5772a