diff --git a/ios/App/App/AppDelegate.swift b/ios/App/App/AppDelegate.swift index 42432e3c4f..334f2e39e3 100644 --- a/ios/App/App/AppDelegate.swift +++ b/ios/App/App/AppDelegate.swift @@ -10,6 +10,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel var navController: UINavigationController? private var pathStack: [String] = ["/"] private var ignoreRoutePopCount = 0 + private lazy var navigationSwipeGesture: UISwipeGestureRecognizer = { + let gesture = UISwipeGestureRecognizer(target: self, action: #selector(handleNavigationSwipe(_:))) + gesture.direction = .right // allow back/open without edge-only gesture + gesture.cancelsTouchesInView = false + return gesture + }() private lazy var sidebarCloseGesture: UISwipeGestureRecognizer = { let gesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSidebarCloseSwipe(_:))) gesture.direction = .left // right-to-left swipe to close @@ -211,6 +217,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { guard let current = viewController as? NativePageViewController else { return } SharedWebViewController.instance.attach(to: current) + attachNavigationSwipeGesture() updateSidebarGestureAttachment(for: current) } @@ -227,6 +234,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel return pageVC.targetPath == "/left-sidebar" } + private func attachNavigationSwipeGesture() { + guard let nav = navController else { return } + if let edgePan = nav.interactivePopGestureRecognizer { + navigationSwipeGesture.require(toFail: edgePan) + } + if navigationSwipeGesture.view !== nav.view { + nav.view.addGestureRecognizer(navigationSwipeGesture) + } + } + private func updateSidebarGestureAttachment(for vc: NativePageViewController) { guard let nav = navController else { return } if isLeftSidebar(vc) { @@ -238,6 +255,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel } } + @objc private func handleNavigationSwipe(_ gesture: UISwipeGestureRecognizer) { + guard gesture.state == .ended else { return } + guard let nav = navController else { return } + + if nav.viewControllers.count > 1 { + nav.popViewController(animated: true) + return + } + + if shouldAllowSidebarOpen("/left-sidebar") { + print("debug open left sidebar") + openURL("logseq://mobile/go/left-sidebar") + } + } + @objc private func handleSidebarCloseSwipe(_ gesture: UISwipeGestureRecognizer) { guard gesture.state == .ended else { return } guard let nav = navController, diff --git a/src/main/mobile/deeplink.cljs b/src/main/mobile/deeplink.cljs index 666f66f538..66ee9eb036 100644 --- a/src/main/mobile/deeplink.cljs +++ b/src/main/mobile/deeplink.cljs @@ -11,6 +11,7 @@ [frontend.util.text :as text-util] [goog :refer [Uri]] [logseq.common.util :as common-util] + [mobile.state :as mobile-state] [promesa.core :as p])) (def *link-to-another-graph (atom false)) @@ -38,6 +39,8 @@ (state/pub-event! [:mobile/start-audio-record]) (and (= hostname "mobile") (= pathname "/go/quick-add")) (editor-handler/show-quick-add) + (and (= hostname "mobile") (= pathname "/go/left-sidebar")) + (mobile-state/open-left-sidebar!) (= hostname "graph") (let [graph-name (some-> pathname (string/replace "/" "") diff --git a/src/main/mobile/state.cljs b/src/main/mobile/state.cljs index d89b2714b4..4c4c25502f 100644 --- a/src/main/mobile/state.cljs +++ b/src/main/mobile/state.cljs @@ -67,7 +67,6 @@ (defn close-left-sidebar! [] (reset! *left-sidebar-open? false) - (redirect-to-tab! "home") (state/pub-event! [:mobile/redirect-to {:k :home}])) (defonce *log (atom []))