Skip to content

Commit

Permalink
Tie the PushLink destination to the specific VC
Browse files Browse the repository at this point in the history
Previously this was just checking the VC class, which could
match for multiple links.
  • Loading branch information
helje5 committed Apr 30, 2022
1 parent ef4e85a commit ffbf9ed
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Sources/ViewController/NavigationLink/PushLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,29 @@ public struct PushLink<VC, CV, Label>: 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")
}
}
Expand Down

0 comments on commit ffbf9ed

Please sign in to comment.