Tienson Qin 3 месяцев назад
Родитель
Сommit
7fac63544c

+ 6 - 1
ios/App/App/NativeTopBarPlugin.swift

@@ -33,11 +33,16 @@ public class NativeTopBarPlugin: CAPPlugin, CAPBridgedPlugin {
         let rightButtons = call.getArray("rightButtons", JSObject.self) ?? []
         let backgroundColorHex = call.getString("backgroundColor")
         let tintColorHex = call.getString("tintColor")
+        let hidden = call.getBool("hidden") ?? false
         let titleClickable = call.getBool("titleClickable") ?? false
 
         DispatchQueue.main.async { [weak self] in
             guard let self = self else { return }
-            nav.setNavigationBarHidden(false, animated: false)
+            nav.setNavigationBarHidden(hidden, animated: true)
+            guard !hidden else {
+                call.resolve()
+                return
+            }
 
             let appearance = UINavigationBarAppearance()
             appearance.configureWithOpaqueBackground()

+ 0 - 3
src/main/mobile/components/app.cljs

@@ -18,7 +18,6 @@
             [mobile.bottom-tabs :as bottom-tabs]
             [mobile.components.editor-toolbar :as editor-toolbar]
             [mobile.components.header :as mobile-header]
-            [mobile.components.left-sidebar :as mobile-left-sidebar]
             [mobile.components.popup :as popup]
             [mobile.components.search :as search]
             [mobile.components.selection-toolbar :as selection-toolbar]
@@ -223,8 +222,6 @@
 
       (mobile-header/header tab login?)
 
-      (mobile-left-sidebar/left-sidebar)
-
       ;; bottom tabs
       (when-not (mobile-util/native-ios?)
         (ui-silk/app-silk-tabs))

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

@@ -131,6 +131,8 @@
              (not @native-top-bar-listener?))
     (.addListener mobile-util/native-top-bar "buttonTapped"
                   (fn [^js e]
+                    (prn :debug :id (.-id e)
+                         :sidebar-open? (mobile-state/left-sidebar-open?))
                     (case (.-id e)
                       "menu" (if (mobile-state/left-sidebar-open?)
                                (mobile-state/close-left-sidebar!)
@@ -142,10 +144,11 @@
     (reset! native-top-bar-listener? true)))
 
 (defn- configure-native-top-bar!
-  [{:keys [tab title]}]
+  [{:keys [tab title hidden?]}]
   (when (mobile-util/native-ios?)
     (let [base {:title title
-                :tintColor "#1f2937"}
+                :tintColor "#1f2937"
+                :hidden (boolean hidden?)}
           left-buttons (when (= tab "home")
                          [{:id "menu" :systemIcon "line.3.horizontal"}])
           right-buttons (cond

+ 2 - 26
src/main/mobile/components/left_sidebar.cljs

@@ -1,37 +1,13 @@
 (ns mobile.components.left-sidebar
   "Mobile left sidebar"
   (:require [frontend.components.left-sidebar :as app-left-sidebar]
-            [logseq.shui.silkhq :as silkhq]
-            [mobile.bottom-tabs :as bottom-tabs]
-            [mobile.state :as mobile-state]
             [rum.core :as rum]))
 
-(rum/defc sidebar-content
+(rum/defc left-sidebar
   []
-  [:div.w-full.app-silk-popup-content-inner.px-2
+  [:div.px-2
    [:div.left-sidebar-inner
     [:div.sidebar-contents-container.mt-11
      {:class "!gap-4"}
      (app-left-sidebar/sidebar-favorites)
      (app-left-sidebar/sidebar-recent-pages)]]])
-
-(rum/defc left-sidebar < rum/reactive
-  []
-  (when (empty? (rum/react mobile-state/*modal-blocks))
-    (let [open? (rum/react mobile-state/*left-sidebar-open?)]
-      (when open?
-        (bottom-tabs/hide!))
-      (silkhq/sidebar-sheet
-       {:presented (boolean open?)
-        :onPresentedChange (fn [v]
-                             (when (false? v)
-                               (mobile-state/close-left-sidebar!)
-                               (bottom-tabs/show!)))}
-       (silkhq/sidebar-sheet-portal
-        (silkhq/sidebar-sheet-view
-         {:class "app-silk-sidebar-sheet-view"}
-         (silkhq/sidebar-sheet-backdrop)
-         (silkhq/sidebar-sheet-content
-          {:class "app-silk-sidebar-sheet-content"}
-          (silkhq/sidebar-sheet-handle)
-          (sidebar-content))))))))

+ 0 - 233
src/main/mobile/components/modal.cljs

@@ -1,233 +0,0 @@
-(ns mobile.components.modal
-  "Mobile modal"
-  (:require ["../externals.js"]
-            [cljs-bean.core :as bean]
-            [frontend.components.page :as page]
-            [frontend.db :as db]
-            [frontend.handler.notification :as notification]
-            [frontend.handler.page :as page-handler]
-            [frontend.state :as state]
-            [frontend.ui :as ui]
-            [frontend.util :as util]
-            [logseq.db.frontend.entity-util :as entity-util]
-            [logseq.shui.hooks :as hooks]
-            [logseq.shui.silkhq :as silkhq]
-            [logseq.shui.ui :as shui]
-            [mobile.bottom-tabs :as bottom-tabs]
-            [mobile.components.ui :as mobile-ui]
-            [mobile.init :as init]
-            [mobile.state :as mobile-state]
-            [promesa.core :as p]
-            [rum.core :as rum]))
-
-(rum/defc back-or-close-button < rum/reactive
-  []
-  (let [block-modal (rum/react mobile-state/*modal-blocks)
-        blocks-history (rum/react mobile-state/*blocks-navigation-history)
-        back? (and (seq block-modal)
-                   (> (count blocks-history) 1))]
-    (shui/button
-     {:variant :text
-      :size :sm
-      :on-click (fn [_e]
-                  (if back?
-                    (mobile-state/pop-navigation-history!)
-                    (mobile-state/close-block-modal!)))
-      :class "-ml-2"}
-     (shui/tabler-icon (if back? "arrow-left" "chevron-down") {:size 24}))))
-
-(defn- skip-touch-check?
-  []
-  (or (seq @mobile-state/*popup-data)
-      (:mobile/show-action-bar? @state/state)
-      (state/editing?)))
-
-(defn- setup-sidebar-touch-swipe!
-  [ref]
-  (let [touch-start-x (atom 0)
-        touch-start-y (atom 0)
-        has-triggered? (atom false)
-        blocking-scroll? (atom false)
-        max-y (atom 0)
-        min-y (atom 0)
-        swipe-trigger-distance 50         ;; when to actually open sidebar
-        horiz-intent-threshold 10         ;; when to start blocking scroll
-        max-vertical-drift 50
-        on-touch-start (fn [^js e]
-                         (when-not (skip-touch-check?)
-                           (let [t (aget e "touches" 0)]
-                             (reset! touch-start-x (.-pageX t))
-                             (reset! touch-start-y (.-pageY t))
-                             (reset! has-triggered? false)
-                             (reset! blocking-scroll? false)
-                             (reset! max-y (.-pageY t))
-                             (reset! min-y (.-pageY t)))))
-
-        on-touch-move (fn [^js e]
-                        (when-not (skip-touch-check?)
-                          (let [t (aget e "touches" 0)
-                                dx (- (.-pageX t) @touch-start-x)
-                                dy (js/Math.abs (- @max-y @min-y))
-                                _ (reset! max-y (max (.-pageY t) @max-y))
-                                _ (reset! min-y (min (.-pageY t) @min-y))
-                                horizontal-intent (and (> dx horiz-intent-threshold)
-                                                       (> dx dy))
-                                is-horizontal-swipe (and (> dx swipe-trigger-distance)
-                                                         (< dy max-vertical-drift))]
-                            ;; as soon as we detect horizontal intent, block vertical scrolling
-                            (when (or @blocking-scroll? horizontal-intent)
-                              (reset! blocking-scroll? true)
-                              (.preventDefault e))       ;; <-- stops page from scrolling
-
-                            (when (and (not @has-triggered?)
-                                       is-horizontal-swipe)
-                              (reset! has-triggered? true)
-                              (mobile-state/pop-navigation-history!)))))
-
-        on-touch-end (fn [_]
-                       (reset! blocking-scroll? false))]
-
-    ;; IMPORTANT: passive:false so preventDefault actually works
-    (.addEventListener ref "touchstart" on-touch-start #js {:passive false})
-    (.addEventListener ref "touchmove"  on-touch-move  #js {:passive false})
-    (.addEventListener ref "touchend"   on-touch-end   #js {:passive false})
-    (.addEventListener ref "touchcancel" on-touch-end  #js {:passive false})
-
-    ;; cleanup
-    #(do
-       (.removeEventListener ref "touchstart" on-touch-start)
-       (.removeEventListener ref "touchmove"  on-touch-move)
-       (.removeEventListener ref "touchend"   on-touch-end)
-       (.removeEventListener ref "touchcancel" on-touch-end))))
-
-(rum/defc block-cp
-  [block]
-  [:<>
-   (mobile-ui/keep-keyboard-virtual-input "in-modal")
-   [:div.app-silk-scroll-content-inner
-    ;; block page content
-    [:div.block-modal-page-content
-     (mobile-ui/classic-app-container-wrap
-      (page/page-cp (db/entity [:block/uuid (:block/uuid block)])))]]])
-
-(rum/defc block-sheet-topbar
-  [block {:keys [favorited? set-favorited!]}]
-
-  (let [close! mobile-state/close-block-modal!]
-    [:div.flex.justify-between.items-center.block-modal-page-header
-     (back-or-close-button)
-
-     [:span.flex.items-center.-mr-2
-      (when-let [block-id-str (str (:block/uuid block))]
-        (shui/button
-         {:variant :text
-          :size :sm
-          :class (when favorited? "!text-yellow-800")
-          :on-click #(-> (if favorited?
-                           (page-handler/<unfavorite-page! block-id-str)
-                           (page-handler/<favorite-page! block-id-str))
-                         (p/then (fn [] (set-favorited! (not favorited?)))))}
-         (shui/tabler-icon (if favorited? "star-filled" "star") {:size 20})))
-      (shui/button
-       {:variant :text
-        :size :sm
-        :on-click (fn []
-                    (mobile-ui/open-popup!
-                     (fn []
-                       [:div.-mx-2
-                        (ui/menu-link
-                         {:on-click #(mobile-ui/close-popup!)}
-                         [:span.text-lg.flex.gap-2.items-center
-                          (shui/tabler-icon "copy" {:class "opacity-80" :size 22})
-                          "Copy"])
-
-                        (ui/menu-link
-                         {:on-click #(-> (shui/dialog-confirm!
-                                          (str "⚠️ Are you sure you want to delete this "
-                                               (if (entity-util/page? block) "page" "block")
-                                               "?"))
-                                         (p/then
-                                          (fn []
-                                            (mobile-ui/close-popup!)
-                                            (some->
-                                             (:block/uuid block)
-                                             (page-handler/<delete!
-                                              (fn [] (close!))
-                                              {:error-handler
-                                               (fn [{:keys [msg]}]
-                                                 (notification/show! msg :warning))})))))}
-                         [:span.text-lg.flex.gap-2.items-center.text-red-700
-                          (shui/tabler-icon "trash" {:class "opacity-80" :size 22})
-                          "Delete"])])
-                     {:title "Actions"
-                      :default-height false
-                      :type :action-sheet}))}
-       (shui/tabler-icon "dots-vertical" {:size 20}))]]))
-
-(rum/defc sheet-content
-  [block favorited? set-favorited!]
-  (let [*ref (hooks/use-ref nil)]
-    (hooks/use-effect!
-     (fn []
-       (when-let [ref (rum/deref *ref)]
-         (setup-sidebar-touch-swipe! ref)))
-     [(rum/deref *ref)])
-    (silkhq/depth-sheet-content
-     {:class "app-silk-depth-sheet-content"
-      :ref *ref}
-     (block-sheet-topbar block {:favorited? favorited?
-                                :set-favorited! set-favorited!})
-     (silkhq/scroll
-      {:as-child true}
-      (silkhq/scroll-view
-       {:class "app-silk-scroll-view"
-        :scrollGestureTrap {:yEnd true}}
-       (silkhq/scroll-content
-        {:class "app-silk-scroll-content"}
-        (block-cp block)))))))
-
-(rum/defc block-sheet
-  [block]
-  (let [block (when-let [id (:block/uuid block)]
-                (db/entity [:block/uuid id]))
-        open? (boolean block)
-        [favorited? set-favorited!] (hooks/use-state false)]
-    (hooks/use-effect!
-     (fn []
-       (set-favorited! (page-handler/favorited? (str (:block/uuid block)))))
-     [block])
-
-    (hooks/use-effect!
-     (fn []
-       (when open?
-         (bottom-tabs/hide!)
-         (state/clear-edit!)
-         (init/keyboard-hide)))
-     [open?])
-
-    (silkhq/depth-sheet
-     {:presented (boolean open?)
-      :onPresentedChange (fn [v?]
-                           (when (false? v?)
-                             (mobile-state/close-block-modal!)
-                             (state/clear-edit!)
-                             (state/pub-event! [:mobile/keyboard-will-hide])
-                             (bottom-tabs/show!)))}
-     (silkhq/depth-sheet-portal
-      (silkhq/depth-sheet-view
-       {:class "block-modal-page"
-        :inertOutside true
-        :onClickOutside (bean/->js {:dismiss false
-                                    :stopOverlayPropagation false})}
-       (silkhq/depth-sheet-backdrop)
-       (sheet-content block favorited? set-favorited!))))))
-
-(rum/defc blocks-modal < rum/reactive
-  []
-  (let [blocks (rum/react mobile-state/*modal-blocks)
-        light-theme? (= "light" (:ui/theme @state/state))]
-    (when light-theme?
-      (if (seq blocks)
-        (util/set-theme-dark)
-        (util/set-theme-light)))
-    (block-sheet (first blocks))))

+ 5 - 0
src/main/mobile/core.cljs

@@ -12,6 +12,7 @@
             [frontend.util :as util]
             [lambdaisland.glogi :as log]
             [logseq.shui.ui :as shui]
+            [mobile.bottom-tabs :as bottom-tabs]
             [mobile.components.app :as app]
             [mobile.events]
             [mobile.init :as init]
@@ -42,7 +43,11 @@
                    :path-params (:path-params route)
                    :query-params (:query-params route)}
            :path path})
+         (when (not= route-name :left-sidebar)
+           (reset! mobile-state/*left-sidebar-open? false)
+           (bottom-tabs/show!))
          (case route-name
+           :left-sidebar (bottom-tabs/hide!)
            :page
            (let [id-str (get-in route [:path-params :name])]
              (when (util/uuid-string? id-str)

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

@@ -5,7 +5,8 @@
             [frontend.state :as state]
             [mobile.components.recorder :as recorder]
             [mobile.init :as init]
-            [mobile.state :as mobile-state]))
+            [mobile.state :as mobile-state]
+            [reitit.frontend.easy :as rfe]))
 
 (defmethod events/handle :mobile/clear-edit [_]
   (state/clear-edit!)
@@ -19,3 +20,6 @@
 
 (defmethod events/handle :mobile/start-audio-record [_]
   (recorder/record! {:save-to-today? true}))
+
+(defmethod events/handle :mobile/redirect-to [[_ {:keys [k params query]}]]
+  (rfe/push-state k params query))

+ 5 - 0
src/main/mobile/routes.cljs

@@ -1,10 +1,15 @@
 (ns mobile.routes
   (:require [frontend.components.page :as page]
+            [mobile.components.left-sidebar :as mobile-left-sidebar]
             [mobile.components.search :as search]))
 
 (def routes
   [["/"
     {:name :home}]
+   ["/left-sidebar"
+    {:name :left-sidebar
+     :view (fn []
+             (mobile-left-sidebar/left-sidebar))}]
    ["/page/:name"
     {:name :page
      :view (fn [route-match]

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

@@ -48,11 +48,8 @@
 
 (defn open-left-sidebar!
   []
-  (reset! *left-sidebar-open? true))
-
-(defn close-left-sidebar!
-  []
-  (reset! *left-sidebar-open? false))
+  (reset! *left-sidebar-open? true)
+  (state/pub-event! [:mobile/redirect-to {:k :left-sidebar}]))
 
 (defn left-sidebar-open?
   []
@@ -61,6 +58,12 @@
 (defn redirect-to-tab! [name]
   (set-tab! (str name)))
 
+(defn close-left-sidebar!
+  []
+  (reset! *left-sidebar-open? false)
+  (redirect-to-tab! "home")
+  (state/pub-event! [:mobile/redirect-to {:k :home}]))
+
 (defonce *log (atom []))
 (defn log-append!
   [record]