Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Examples/CaseStudies/UIKit/ErasedNavigationStackController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ private class NumberFeatureViewController: UIViewController {
self.number = number
super.init(nibName: nil, bundle: nil)
title = "Feature \(number)"

navigationDestination(for: String.self) { string in
StringFeatureViewController(string: string)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand All @@ -89,10 +93,6 @@ private class NumberFeatureViewController: UIViewController {
super.viewDidLoad()
view.backgroundColor = .systemBackground

navigationDestination(for: String.self) { string in
StringFeatureViewController(string: string)
}

let numberButton = UIButton(
type: .system,
primaryAction: UIAction { [weak self] _ in
Expand Down Expand Up @@ -137,6 +137,10 @@ private class StringFeatureViewController: UIViewController {
self.string = string
super.init(nibName: nil, bundle: nil)
title = "Feature '\(string)'"

navigationDestination(for: Bool.self) { bool in
BoolFeatureViewController(bool: bool)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand All @@ -145,10 +149,6 @@ private class StringFeatureViewController: UIViewController {
super.viewDidLoad()
view.backgroundColor = .systemBackground

navigationDestination(for: Bool.self) { bool in
BoolFeatureViewController(bool: bool)
}

let numberButton = UIButton(
type: .system,
primaryAction: UIAction { [weak self] _ in
Expand Down
20 changes: 18 additions & 2 deletions Sources/UIKitNavigation/Navigation/NavigationStackController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,19 @@
)
return
}
stackController.path.append(.lazy(.element(value)))
withUITransaction(\.stackController, stackController) {
stackController.path.append(.lazy(.element(value)))
}
Comment on lines +341 to +343
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes things just for the case study, but because deep linking can happen directly from state we would need to explore a more universal solution to ship this.

}

public func navigationDestination<D: Hashable>(
for data: D.Type,
destination: @escaping (D) -> UIViewController
) {
guard let navigationController = navigationController ?? self as? UINavigationController
guard
let navigationController = UITransaction.current.stackController
?? navigationController
?? self as? UINavigationController
else {
reportIssue(
"""
Expand Down Expand Up @@ -442,4 +447,15 @@
}
}
}

private extension UITransaction {
var stackController: NavigationStackController? {
get { self[NavigationStackControllerKey.self] }
set { self[NavigationStackControllerKey.self] = newValue }
}
}

private enum NavigationStackControllerKey: UITransactionKey {
static let defaultValue: NavigationStackController? = nil
}
#endif