Skip to content

Commit

Permalink
refactor native controller example
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Sep 10, 2023
1 parent f0db486 commit a4ab45e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import SwiftUI

class NumbersViewController: UIHostingController<NumbersView> {
init() {
super.init(rootView: NumbersView())
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad(); title = "Numbers"
convenience init(title: String) {
self.init(rootView: NumbersView())
self.title = title
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension TurboNavigationController {

private func isClearAll(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "clear-all"
}
}

private func isReplaceAll(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "replace-all"
Expand All @@ -75,13 +75,13 @@ extension TurboNavigationController {
if let viewController = properties["view-controller"] as? String {
switch viewController {
case "numbers":
return NumbersViewController()
return NumbersViewController(title: "Numbers")
default:
return ViewController(url: url)
assertionFailure("Invalid view controller, defaulting to WebView")
}
} else {
return ViewController(url: url)
}

return ViewController(url: url)
}

private func navigate(to viewController: UIViewController, action: VisitAction, properties: PathProperties = [:]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import SwiftUI

class NumbersViewController: UIHostingController<NumbersView> {
init() {
super.init(rootView: NumbersView())
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad(); title = "Numbers"
convenience init(title: String) {
self.init(rootView: NumbersView())
self.title = title
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension TurboNavigationController {

private func isClearAll(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "clear-all"
}
}

private func isReplaceAll(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "replace-all"
Expand All @@ -75,13 +75,13 @@ extension TurboNavigationController {
if let viewController = properties["view-controller"] as? String {
switch viewController {
case "numbers":
return NumbersViewController()
return NumbersViewController(title: "Numbers")
default:
return ViewController(url: url)
assertionFailure("Invalid view controller, defaulting to WebView")
}
} else {
return ViewController(url: url)
}

return ViewController(url: url)
}

private func navigate(to viewController: UIViewController, action: VisitAction, properties: PathProperties = [:]) {
Expand Down

0 comments on commit a4ab45e

Please sign in to comment.