From ffbf9ed32f8736995da1d7a786be92692c97515a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 30 Apr 2022 14:42:21 +0200 Subject: [PATCH] Tie the `PushLink` destination to the specific VC Previously this was just checking the VC class, which could match for multiple links. --- .../NavigationLink/PushLink.swift | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Sources/ViewController/NavigationLink/PushLink.swift b/Sources/ViewController/NavigationLink/PushLink.swift index 977c2b7..6571eab 100644 --- a/Sources/ViewController/NavigationLink/PushLink.swift +++ b/Sources/ViewController/NavigationLink/PushLink.swift @@ -171,16 +171,29 @@ public struct PushLink: View } @ViewBuilder private var destination: some View { - if let presentedVC = parentViewController - .presentedViewController(of: VC.self, mode: mode) - { - contentView - .controlled(by: presentedVC) - .environment(\.viewControllerPresentationMode, .navigation) - .navigationTitle(presentedVC.navigationTitle) + if let activeVC = childViewController { + if let presentedVC = activeVC as? VC { + if let presentation = + parentViewController.activePresentation(for: presentedVC), + presentation.mode == mode + { + contentView + .controlled(by: presentedVC) + .environment(\.viewControllerPresentationMode, .navigation) + .navigationTitle(presentedVC.navigationTitle) + } + else { + SwiftUI.Label("Error: The linked VC is not being presented as a link", + systemImage: "exclamationmark.triangle") + } + } + else { + SwiftUI.Label("Error: The linked VC has an unexpected type!", + systemImage: "exclamationmark.triangle") + } } else { - SwiftUI.Label("Error: Missing/wrong presented VC", + SwiftUI.Label("Linked VC is not yet being presented.", systemImage: "exclamationmark.triangle") } }