Переглянути джерело

improve(mobile): back navigation for android

charlie 4 роки тому
батько
коміт
62a8ed8ff4
3 змінених файлів з 24 додано та 4 видалено
  1. 1 0
      package.json
  2. 6 4
      src/main/frontend/handler.cljs
  3. 17 0
      src/main/frontend/mobile/core.cljs

+ 1 - 0
package.json

@@ -63,6 +63,7 @@
     "dependencies": {
         "@capacitor/android": "3.2.2",
         "@capacitor/core": "3.2.2",
+        "@capacitor/app": "1.0.6",
         "@capacitor/filesystem": "1.0.3",
         "@capacitor/ios": "3.2.2",
         "@capacitor/splash-screen": "1.1.3",

+ 6 - 4
src/main/frontend/handler.cljs

@@ -17,7 +17,8 @@
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.extensions.srs :as srs]
-            [frontend.mobile.util :as mobile]
+            [frontend.mobile.core :as mobile]
+            [frontend.mobile.util :as mobile-util]
             [frontend.idb :as idb]
             [frontend.modules.instrumentation.core :as instrument]
             [frontend.modules.shortcut.core :as shortcut]
@@ -210,15 +211,16 @@
     (p/let [repos (get-repos)]
       (state/set-repos! repos)
       (restore-and-setup! me repos logged? db-schema)
-      (when (mobile/is-native-platform?)
-        (p/do! (mobile/hide-splash))))
+      (when (mobile-util/is-native-platform?)
+        (p/do! (mobile-util/hide-splash))))
 
     (reset! db/*sync-search-indice-f search/sync-search-indice!)
     (db/run-batch-txs!)
     (file-handler/run-writes-chan!)
     (pool/init-parser-pool!)
     (when (util/electron?)
-      (el/listen!))))
+      (el/listen!))
+    (mobile/init!)))
 
 (defn stop! []
   (prn "stop!"))

+ 17 - 0
src/main/frontend/mobile/core.cljs

@@ -0,0 +1,17 @@
+(ns frontend.mobile.core
+  (:require [frontend.mobile.util :as mobile-util]
+            ["@capacitor/app" :refer [^js App]]
+            [reitit.frontend.easy :as rfe]
+            [clojure.string :as string]))
+
+
+(defn init!
+  []
+  ;; patch back navigation
+  (when (mobile-util/native-android?)
+    (.addListener App "backButton"
+                  #(let [href js/window.location.href]
+                     (if (or (string/ends-with? href "#/")
+                             (string/ends-with? href "/"))
+                       (.exitApp App)
+                       (js/window.history.back))))))