Browse Source

enhance(mobile): replace buggy capture bottom sheet with tab

Tienson Qin 5 days ago
parent
commit
88721b45fb

+ 4 - 39
ios/App/App/LiquidTabsRootView.swift

@@ -163,47 +163,12 @@ private struct LiquidTabs26View: View {
         }
     }
 
-    // MARK: - Helpers to keep the TabView expression simple
-
-    struct CapturePlaceholderView: View {
-        @State private var appear = false
-
-        var body: some View {
-            VStack {
-                Spacer()
-
-                Image(systemName: "tray.fill")
-                  .font(.system(size: 90))
-                  .foregroundColor(.primary)
-                  .opacity(appear ? 0.1 : 0.0)
-                  .onAppear {
-                      appear = false
-                      DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-                          appear = true
-                      }
-                  }
-
-                Spacer()
-            }
-              .frame(maxWidth: .infinity, maxHeight: .infinity)
-              .background(Color.logseqBackground)
-              .ignoresSafeArea()
-        }
-    }
-
     @ViewBuilder
     private func mainTabContent(index: Int, tab: LiquidTab) -> some View {
-        // Special "capture" tab → shows a plain Capture screen
-        if tab.id == "capture" {
-            NavigationStack {
-                CapturePlaceholderView()
-            }
-        } else {
-            // Normal content tab → shared webview
-            NativeNavHost(navController: navController)
-                .ignoresSafeArea()
-                .background(Color.logseqBackground)
-        }
+        // Normal content tab → shared webview
+        NativeNavHost(navController: navController)
+          .ignoresSafeArea()
+          .background(Color.logseqBackground)
     }
 
     @ViewBuilder

+ 5 - 1
src/main/frontend/components/editor.cljs

@@ -794,7 +794,11 @@
       {:node @(::ref state)
        :on-hide (fn [_state e type]
                   (when-not (= type :esc)
-                    (let [editing-another-block? (.closest (.-target e) ".ls-block")]
+                    (let [target (.-target e)
+                          block-container (.closest target ".ls-block")
+                          editing-another-block? (and block-container
+                                                      (not (dom/has-class? block-container "block-add-button"))
+                                                      (gdom/contains block-container target))]
                       (editor-on-hide state type e editing-another-block?))))})))
   (mixins/event-mixin setup-key-listener!)
   lifecycle/lifecycle

+ 8 - 5
src/main/frontend/handler/editor.cljs

@@ -4044,7 +4044,7 @@
            (when query-block
              (save-block-inner! query-block current-query {})))))))))
 
-(defn show-quick-add
+(defn quick-add-ensure-new-block-exists!
   []
   (let [graph (state/get-current-repo)]
     (p/do!
@@ -4061,10 +4061,13 @@
        (when (empty? children')
          (api-insert-new-block! "" {:page (:block/uuid add-page)
                                     :container-id :unknown-container
-                                    :replace-empty-target? false})))
-     (state/pub-event! [(if (util/mobile?)
-                          :dialog/mobile-quick-add
-                          :dialog/quick-add)]))))
+                                    :replace-empty-target? false}))))))
+
+(defn show-quick-add
+  []
+  (p/do!
+   (quick-add-ensure-new-block-exists!)
+   (state/pub-event! [:dialog/quick-add])))
 
 (defn quick-add-blocks!
   []

+ 1 - 1
src/main/frontend/state.cljs

@@ -2004,7 +2004,7 @@ Similar to re-frame subscriptions"
             (when (and move-cursor? (not (block-component-editing?)))
               (cursor/move-cursor-to input pos))
 
-            (when (or (util/mobile?) (mobile-util/native-platform?))
+            (when (mobile-util/native-platform?)
               (set-state! :mobile/show-action-bar? false))))))))
 
 (defn get-git-auto-commit-enabled?

+ 3 - 15
src/main/mobile/bottom_tabs.cljs

@@ -80,26 +80,14 @@
                (editor-handler/keydown-new-block-handler nil))))
          nil)))))
 
-(defonce *previous-tab (atom nil))
 (defonce add-tab-listeners!
   (do
     (add-tab-selected-listener!
      (fn [tab]
-       (if (= tab "capture")
-         (editor-handler/show-quick-add)
-         (do
-           (mobile-state/set-tab! tab)
+       (mobile-state/set-tab! tab)
 
-           (case tab
-             "home"
-             (when-not (= @*previous-tab "capture")
-               (util/scroll-to-top false))
-             ;; TODO: support longPress detection
-             ;; (if (= "longPress" interaction)
-             ;;   (state/pub-event! [:mobile/start-audio-record])
-             ;;   (editor-handler/show-quick-add))
-             nil)))
-       (reset! *previous-tab tab)))
+       (when (= "home" tab)
+         (util/scroll-to-top false))))
 
     (add-watch mobile-state/*tab ::select-tab
                (fn [_ _ _old new]

+ 15 - 1
src/main/mobile/components/app.cljs

@@ -2,7 +2,9 @@
   "App root"
   (:require ["../externals.js"]
             [frontend.components.journal :as journal]
+            [frontend.components.quick-add :as quick-add]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.editor :as editor-handler]
             [frontend.mobile.util :as mobile-util]
             [frontend.rum :as frum]
             [frontend.state :as state]
@@ -23,6 +25,7 @@
             [mobile.components.selection-toolbar :as selection-toolbar]
             [mobile.components.ui :as ui-component]
             [mobile.state :as mobile-state]
+            [promesa.core :as p]
             [rum.core :as rum]))
 
 (rum/defc journals
@@ -85,6 +88,16 @@
        #(.removeEventListener js/window "orientationchange" handle-size!)))
    []))
 
+(rum/defc capture <
+  {:did-mount (fn [state]
+                (p/do!
+                 (editor-handler/quick-add-ensure-new-block-exists!)
+                 ;; (editor-handler/quick-add-open-last-block!)
+                 )
+                state)}
+  []
+  (quick-add/quick-add))
+
 (rum/defc other-page < rum/static
   [route-view tab route-match]
   (let [page-view? (= (get-in route-match [:data :name]) :page)]
@@ -96,7 +109,8 @@
        (cond
          (= tab "graphs") (graphs/page)
          (= tab "go to") (favorites/favorites)
-         (= tab "search") (search/search)))]))
+         (= tab "search") (search/search)
+         (= tab "capture") (capture)))]))
 
 (rum/defc main-content < rum/static
   [tab route-match]

+ 14 - 37
src/main/mobile/components/editor_toolbar.cljs

@@ -14,7 +14,6 @@
             [logseq.shui.hooks :as hooks]
             [mobile.components.recorder :as recorder]
             [mobile.init :as mobile-init]
-            [mobile.state :as mobile-state]
             [promesa.core :as p]
             [rum.core :as rum]))
 
@@ -148,42 +147,21 @@
               (state/clear-edit!)
               (mobile-init/keyboard-hide))})
 
-(defn- capture-action
-  []
-  {:id "capture"
-   :title "Capture"
-   :system-icon "paperplane"
-   :handler (fn []
-              (state/clear-edit!)
-              (mobile-init/keyboard-hide)
-              (editor-handler/quick-add-blocks!))})
-
 (defn- toolbar-actions
-  [quick-add?]
-  (let [audio (audio-action)
-        keyboard (keyboard-action)
-        main-actions (if quick-add?
-                       [(undo-action)
-                        (todo-action)
-                        audio
-                        (camera-action)
-                        (tag-action)
-                        (page-ref-action)
-                        (indent-outdent-action false)
-                        (indent-outdent-action true)
-                        (redo-action)]
-                       [(undo-action)
-                        (todo-action)
-                        (indent-outdent-action false)
-                        (indent-outdent-action true)
-                        (tag-action)
-                        (camera-action)
-                        (page-ref-action)
-                        audio
-                        (slash-action)
-                        (redo-action)])]
+  []
+  (let [keyboard (keyboard-action)
+        main-actions [(undo-action)
+                      (todo-action)
+                      (indent-outdent-action false)
+                      (indent-outdent-action true)
+                      (tag-action)
+                      (camera-action)
+                      (page-ref-action)
+                      (audio-action)
+                      (slash-action)
+                      (redo-action)]]
     {:main main-actions
-     :trailing (if quick-add? (capture-action) keyboard)}))
+     :trailing keyboard}))
 
 (defn- action->native
   [{:keys [id title system-icon]}]
@@ -237,9 +215,8 @@
   []
   (let [editing? (state/sub :editor/editing?)
         code-block? (state/sub :editor/code-block-context)
-        quick-add? (mobile-state/quick-add-open?)
         show? (and (not code-block?)
                    editing?)
-        actions (toolbar-actions quick-add?)]
+        actions (toolbar-actions)]
     (when (mobile-util/native-ios?)
       (native-toolbar show? actions))))

+ 13 - 2
src/main/mobile/components/header.cljs

@@ -9,6 +9,7 @@
             [frontend.db.async :as db-async]
             [frontend.db.conn :as db-conn]
             [frontend.flows :as flows]
+            [frontend.handler.editor :as editor-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.page :as page-handler]
             [frontend.handler.route :as route-handler]
@@ -114,6 +115,10 @@
                     (case (.-id e)
                       "title" (open-graph-switch!)
                       "calendar" (open-journal-calendar!)
+                      "capture" (do
+                                  (state/clear-edit!)
+                                  (editor-handler/quick-add-blocks!))
+                      "audio-record" (state/pub-event! [:mobile/start-audio-record])
                       "add-graph" (state/pub-event! [:graph/new-db-graph])
                       "home-setting" (open-home-settings-actions!)
                       "graph-setting" (open-graph-settings-actions!)
@@ -146,8 +151,11 @@
           base {:title title
                 :hidden (boolean hidden?)}
           page? (= route-name :page)
-          left-buttons (when (and (= tab "home") (nil? route-view))
-                         [(conj {:id "calendar" :systemIcon "calendar"})])
+          left-buttons (cond
+                         (and (= tab "home") (nil? route-view))
+                         [(conj {:id "calendar" :systemIcon "calendar"})]
+                         (and (= tab "capture") (nil? route-view))
+                         [(conj {:id "audio-record" :systemIcon "waveform"})])
           right-buttons (cond
                           page?
                           (into [{:id "page-setting" :systemIcon "ellipsis"}
@@ -165,6 +173,9 @@
                           [{:id "graph-setting" :systemIcon "ellipsis"}
                            {:id "add-graph" :systemIcon "plus"}]
 
+                          (= tab "capture")
+                          [{:id "capture" :systemIcon "paperplane"}]
+
                           :else nil)
           header (cond-> base
                    left-buttons (assoc :leftButtons left-buttons)

+ 9 - 20
src/main/mobile/components/popup.cljs

@@ -1,7 +1,6 @@
 (ns mobile.components.popup
   "Mobile popup"
-  (:require [frontend.handler.editor :as editor-handler]
-            [frontend.mobile.util :as mobile-util]
+  (:require [frontend.mobile.util :as mobile-util]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [logseq.shui.popup.core :as shui-popup]
@@ -42,28 +41,18 @@
 
 (defn- handle-native-sheet-state!
   [^js data]
-  (let [presenting? (.-presenting data)
+  (let [;; presenting? (.-presenting data)
         dismissing? (.-dismissing data)]
     (cond
-      presenting?
-      (when (mobile-state/quick-add-open?)
-        (mobile-util/mobile-focus-hidden-input)
-        (editor-handler/quick-add-open-last-block!))
-
       dismissing?
       (when (some? @mobile-state/*popup-data)
-        (let [capture-or-audio? (or (mobile-state/quick-add-open?)
-                                    (mobile-state/audio-record-open?))
-              current-tab @mobile-state/*tab]
-          (p/do!
-           (state/pub-event! [:mobile/clear-edit])
-           (mobile-state/set-popup! nil)
-           (reset! *last-popup-data nil)
-           (when (mobile-util/native-ios?)
-             (let [plugin ^js mobile-util/native-editor-toolbar]
-               (.dismiss plugin)))
-           (when (and current-tab capture-or-audio?)
-             (mobile-state/set-tab! current-tab)))))
+        (p/do!
+         (state/pub-event! [:mobile/clear-edit])
+         (mobile-state/set-popup! nil)
+         (reset! *last-popup-data nil)
+         (when (mobile-util/native-ios?)
+           (let [plugin ^js mobile-util/native-editor-toolbar]
+             (.dismiss plugin)))))
 
       :else
       nil)))

+ 1 - 1
src/main/mobile/components/recorder.cljs

@@ -180,7 +180,7 @@
 (defn record!
   [& {:keys [save-to-today?]}]
   (let [editing-id (state/get-edit-input-id)
-        quick-add? (mobile-state/quick-add-open?)]
+        quick-add? (= "capture" @mobile-state/*tab)]
     (set-last-edit-block! nil)
     (if-not (string/blank? editing-id)
       (p/do!

+ 1 - 3
src/main/mobile/deeplink.cljs

@@ -31,13 +31,11 @@
                    (remove #(= (:url %) config/demo-repo))
                    (map :url))
         repo-names (map #(get-graph-name-fn %) repos)]
-    (prn :debug :hostname hostname
-         :pathname pathname)
     (cond
       (and (= hostname "mobile") (= pathname "/go/audio"))
       (state/pub-event! [:mobile/start-audio-record])
       (and (= hostname "mobile") (= pathname "/go/quick-add"))
-      (editor-handler/show-quick-add)
+      (state/pub-event! [:mobile/set-tab "capture"])
       (= hostname "graph")
       (let [graph-name (some-> pathname
                                (string/replace "/" "")

+ 1 - 11
src/main/mobile/events.cljs

@@ -1,9 +1,7 @@
 (ns mobile.events
   "Mobile events"
-  (:require [frontend.components.quick-add :as quick-add]
-            [frontend.handler.events :as events]
+  (:require [frontend.handler.events :as events]
             [frontend.state :as state]
-            [logseq.shui.ui :as shui]
             [mobile.components.recorder :as recorder]
             [mobile.init :as init]
             [mobile.state :as mobile-state]
@@ -13,14 +11,6 @@
   (state/clear-edit!)
   (init/keyboard-hide))
 
-(defmethod events/handle :dialog/mobile-quick-add [_]
-  (shui/popup-show! nil
-                    (fn []
-                      (quick-add/quick-add))
-                    {:id :ls-quick-add
-                     ;; large height to avoid layout shift
-                     :default-height 750}))
-
 (defmethod events/handle :mobile/start-audio-record [_]
   (recorder/record! {:save-to-today? true}))
 

+ 0 - 8
src/main/mobile/state.cljs

@@ -21,14 +21,6 @@
   (when data
     (state/pub-event! [:mobile/clear-edit])))
 
-(defn quick-add-open?
-  []
-  (= :ls-quick-add (get-in @*popup-data [:opts :id])))
-
-(defn audio-record-open?
-  []
-  (= :ls-audio-record (get-in @*popup-data [:opts :id])))
-
 (defonce *log (atom []))
 (defn log-append!
   [record]