Przeglądaj źródła

fix: blank until navigation push transition ends

Tienson Qin 2 miesięcy temu
rodzic
commit
7786de4632
2 zmienionych plików z 30 dodań i 18 usunięć
  1. 28 5
      ios/App/App/AppDelegate.swift
  2. 2 13
      src/main/mobile/core.cljs

+ 28 - 5
ios/App/App/AppDelegate.swift

@@ -195,9 +195,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
     // ---------------------------------------------------------
 
     func navigationController(
-        _ navigationController: UINavigationController,
-        willShow viewController: UIViewController,
-        animated: Bool
+      _ navigationController: UINavigationController,
+      willShow viewController: UIViewController,
+      animated: Bool
     ) {
         guard let toVC = viewController as? NativePageViewController else { return }
         guard let coordinator = navigationController.transitionCoordinator else { return }
@@ -214,6 +214,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
         }
 
         if isPop {
+            // -----------------------------
+            // POP — keep your existing logic
+            // -----------------------------
             let previousStack = pathStack
             if pathStack.count > 1 { _ = pathStack.popLast() }
             if let last = pathStack.last, last != toVC.targetPath {
@@ -250,8 +253,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
                 }
 
                 SharedWebViewController.instance.attach(
-                    to: toVC,
-                    leavePlaceholderInPreviousParent: fromVC != nil
+                  to: toVC,
+                  leavePlaceholderInPreviousParent: fromVC != nil
                 )
 
                 if let snapshot = self.popSnapshotView {
@@ -264,6 +267,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDel
                     self.popSnapshotView = nil
                 }
             }
+        } else {
+            // -----------------------------
+            // PUSH / RESET
+            // -----------------------------
+            // Attach the shared webview to the *destination* page
+            // before/during the animation so it can start rendering immediately.
+            SharedWebViewController.instance.attach(
+              to: toVC,
+              leavePlaceholderInPreviousParent: fromVC != nil
+            )
+
+            coordinator.animate(alongsideTransition: nil) { ctx in
+                if ctx.isCancelled, let fromVC {
+                    // If the push is cancelled (interactive back), put the webview back.
+                    SharedWebViewController.instance.attach(to: fromVC)
+                } else {
+                    // Transition completed → clear any placeholders.
+                    SharedWebViewController.instance.clearPlaceholder()
+                }
+            }
         }
     }
 

+ 2 - 13
src/main/mobile/core.cljs

@@ -60,7 +60,6 @@
   []
   (.render root (app/main)))
 
-(defonce ^:private *route-timeout (atom nil))
 (defn set-router!
   []
   (let [router (rf/router routes nil)]
@@ -71,23 +70,13 @@
          (state/clear-edit!))
        (selection-toolbar/close-selection-bar!)
        (let [route-name (get-in route [:data :name])
-             path (-> js/location .-hash (string/replace-first #"^#" ""))
-             pop? (= :pop @mobile-nav/navigation-source)
-             timeout @*route-timeout]
-         (when timeout
-           (js/clearTimeout timeout))
+             path (-> js/location .-hash (string/replace-first #"^#" ""))]
          (mobile-nav/notify-route-change!
           {:route {:to route-name
                    :path-params (:path-params route)
                    :query-params (:query-params route)}
            :path path})
-
-         (if pop?
-           (route-handler/set-route-match! route)
-           (reset! *route-timeout
-                   (js/setTimeout
-                    #(route-handler/set-route-match! route)
-                    200)))))
+         (route-handler/set-route-match! route)))
 
      ;; set to false to enable HistoryAPI
      {:use-fragment true})))