Browse Source

enhance(mobile): make input into viewport when initial editing

charlie 4 years ago
parent
commit
a72de57627

+ 1 - 3
src/main/frontend/components/header.cljs

@@ -162,7 +162,6 @@
                    (remove #(= (:url %) config/local-repo)))
         electron-mac? (and util/mac? (util/electron?))
         vw-state (state/sub :ui/visual-viewport-state)
-        vw-pending? (state/sub :ui/visual-viewport-pending?)
         show-open-folder? (and (or (nfs/supported?)
                                    (mobile-util/is-native-platform?))
                                (empty? repos)
@@ -172,8 +171,7 @@
       [:div.cp__header#head
        {:class           (util/classnames [{:electron-mac   electron-mac?
                                             :native-ios     (mobile-util/native-ios?)
-                                            :native-android (mobile-util/native-android?)
-                                            :is-vw-pending  (boolean vw-pending?)}])
+                                            :native-android (mobile-util/native-android?)}])
         :on-double-click (fn [^js e]
                            (when-let [target (.-target e)]
                              (when (and (util/electron?)

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

@@ -23,7 +23,7 @@
       (.focus element)
       (when (or (mobile-util/is-native-platform?)
                 (util/mobile?))
-        (js/setTimeout #(util/make-el-into-viewport element 60) 80))))
+        (js/setTimeout #(util/make-el-into-viewport element 60) 64))))
   state)
 
 (defn did-remount!

+ 9 - 0
src/main/frontend/handler/events.cljs

@@ -221,6 +221,15 @@
     (reset! st/*inited? true)
     (st/consume-pending-shortcuts!)))
 
+
+(defmethod handle :mobile/keyboard-will-show [[_]]
+  (when (state/get-left-sidebar-open?)
+    (state/set-left-sidebar-open! false)))
+
+(defmethod handle :mobile/keyboard-did-show [[_]]
+  (when-let [input (state/get-input)]
+    (js/setTimeout #(util/make-el-into-viewport input 60) 64)))
+
 (defn run!
   []
   (let [chan (state/get-events-chan)]

+ 5 - 3
src/main/frontend/mobile/core.cljs

@@ -34,7 +34,9 @@
   (when (mobile-util/native-ios?)
     (let [path (fs/iOS-ensure-documents!)]
       (println "iOS container path: " path))
-    ;; keyboard watcher
+
+    ;; Keyboard watcher
     (.addListener Keyboard "keyboardWillShow"
-                  #(when (state/get-left-sidebar-open?)
-                     (state/set-left-sidebar-open! false)))))
+                  #(state/pub-event! [:mobile/keyboard-will-show]))
+    (.addListener Keyboard "keyboardDidShow"
+                  #(state/pub-event! [:mobile/keyboard-did-show]))))