fix: blank until navigation push transition ends

This commit is contained in:
Tienson Qin
2025-12-04 09:49:41 +08:00
parent 3219b827e6
commit 7786de4632
2 changed files with 30 additions and 18 deletions

View File

@@ -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()
}
}
}
}