enhance: swipe anywhere to go back

This commit is contained in:
Tienson Qin
2025-11-18 21:53:05 +08:00
parent 918e33affd
commit 0a5ebf97d1
3 changed files with 35 additions and 1 deletions

View File

@@ -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,

View File

@@ -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 "/" "")

View File

@@ -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 []))