fix: path bookkeeping

This commit is contained in:
Tienson Qin
2026-05-19 00:12:24 +08:00
parent 466647ef3d
commit efd9380f22
5 changed files with 22 additions and 11 deletions

View File

@@ -34,6 +34,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
// Each stack has its own native VC stack, just like paths.
private var stackViewControllerStacks: [String: [UIViewController]] = [:]
private var routeChangeObserver: NSObjectProtocol?
// ---------------------------------------------------------
// MARK: Helpers
// ---------------------------------------------------------
@@ -278,9 +280,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
// -----------------------------
let previousStack = pathStack
if pathStack.count > 1 {
if let to = toIndex {
pathStack = Array(pathStack.prefix(to + 1))
} else if pathStack.count > 1 {
_ = pathStack.popLast()
}
if pathStack.isEmpty {
pathStack = [toVC.targetPath]
}
if let last = pathStack.last, last != toVC.targetPath {
pathStack[pathStack.count - 1] = toVC.targetPath
}
@@ -382,7 +389,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
// ---------------------------------------------------------
private func observeRouteChanges() {
NotificationCenter.default.addObserver(
if routeChangeObserver != nil {
return
}
routeChangeObserver = NotificationCenter.default.addObserver(
forName: UILocalPlugin.routeChangeNotification,
object: nil,
queue: .main
@@ -417,8 +428,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
let vc = NativePageViewController(path: "/")
nav.setViewControllers([vc], animated: false)
self.setViewControllers([vc], for: "home")
// 👈 Do NOTHING to nav.viewControllers or SharedWebViewController here.
SharedWebViewController.instance.clearPlaceholder()
SharedWebViewController.instance.attach(to: vc)
return
}

View File

@@ -107,8 +107,8 @@ public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
// MARK: - Events to JS
func notifyTabSelected(id: String) {
notifyListeners("tabSelected", data: ["id": id])
func notifyTabSelected(id: String, reselected: Bool = false) {
notifyListeners("tabSelected", data: ["id": id, "reselected": reselected])
}
func notifySearchChanged(query: String) {

View File

@@ -146,7 +146,7 @@ private struct LiquidTabs26View: View {
navController.popToRootViewController(animated: true)
if let id = store.tabId(for: selection) {
LiquidTabsPlugin.shared?.notifyTabSelected(id: id)
LiquidTabsPlugin.shared?.notifyTabSelected(id: id, reselected: true)
}
}
@@ -386,7 +386,7 @@ private struct LiquidTabs16View: View {
// Re-tap: pop to root
if id == store.selectedId {
navController.popToRootViewController(animated: true)
LiquidTabsPlugin.shared?.notifyTabSelected(id: id)
LiquidTabsPlugin.shared?.notifyTabSelected(id: id, reselected: true)
} else {
store.selectedId = id
LiquidTabsPlugin.shared?.notifyTabSelected(id: id)

View File

@@ -49,7 +49,7 @@ import Capacitor
}
// 2) Detach from previous parent
if let previous = currentParent {
if let previous = vc.parent {
vc.willMove(toParent: nil)
vc.view.removeFromSuperview()
vc.removeFromParent()

View File

@@ -82,7 +82,7 @@
(fn [data]
(when-let [id (.-id data)]
(when-not (string/blank? id)
(route-handler/redirect-to-page! id {:push (mobile-util/native-android?)})))))))
(route-handler/redirect-to-page! id {:push (mobile-util/native-platform?)})))))))
(defn add-keyboard-hack-listener!
"Listen for Backspace or Enter while the invisible keyboard field is focused."
@@ -112,7 +112,7 @@
(cond
reselected?
(do
(when (mobile-util/native-android?)
(when (mobile-util/native-platform?)
(mobile-nav/pop-to-root! tab))
(mobile-state/set-tab! tab)
(when (= "home" tab)