Browse Source

enhance(mobile): make editing always in viewport when be close to bottom

charlie 4 years ago
parent
commit
672f181a92
2 changed files with 6 additions and 5 deletions
  1. 3 3
      src/main/frontend/handler/editor/lifecycle.cljs
  2. 3 2
      src/main/frontend/util.cljc

+ 3 - 3
src/main/frontend/handler/editor/lifecycle.cljs

@@ -21,9 +21,9 @@
 
     (when-let [element (gdom/getElement id)]
       (.focus element)
-      (when (and (util/mobile?)
-                 (not (mobile-util/native-ios?)))
-        (js/setTimeout #(util/make-el-into-viewport element 60) 64))))
+      (when (or (mobile-util/is-native-platform?)
+                (util/mobile?))
+        (js/setTimeout #(util/make-el-into-viewport element 60) 80))))
   state)
 
 (defn did-remount!

+ 3 - 2
src/main/frontend/util.cljc

@@ -1491,10 +1491,11 @@
 #?(:cljs
    (defn make-el-into-viewport
      [^js/HTMLElement el offset]
-     (let [wrap-height (.-clientHeight js/document.documentElement)
+     (let [viewport-height (or (.-height js/window.visualViewport)
+                               (.-clientHeight js/document.documentElement))
            target-bottom (.-bottom (.getBoundingClientRect el))]
        (when (> (+ target-bottom (or (safe-parse-int offset) 0))
-                wrap-height)
+                viewport-height)
          (.scrollIntoView el #js {:block "center" :behavior "smooth"})))))
 
 #?(:cljs