Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Navigation Stack Controller's initializers to be required #199

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ final class StaticNavigationStackController: NavigationStackController, UIKitCas
let isPresentedInSheet = true
private var model: Model!

@MainActor
convenience init() {
@UIBindable var model = Model()
convenience init(model: Model) {
@UIBindable var model = model
self.init(path: $model.path) {
RootViewController(model: model)
}
Expand Down Expand Up @@ -170,5 +169,5 @@ private class FeatureViewController: UIViewController {
}

#Preview {
StaticNavigationStackController()
StaticNavigationStackController(model: StaticNavigationStackController.Model())
}
2 changes: 1 addition & 1 deletion Examples/CaseStudies/UIKit/UIKitCaseStudies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct UIKitCaseStudiesView: View {
ConciseEnumNavigationViewController()
}
CaseStudyGroupView("Stack navigation") {
StaticNavigationStackController()
StaticNavigationStackController(model: StaticNavigationStackController.Model())
ErasedNavigationStackController(model: ErasedNavigationStackController.Model())
// TODO: state restoration
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,36 @@
set { pathDelegate.base = newValue }
}

public convenience init<Data: RandomAccessCollection & RangeReplaceableCollection>(
public required init<Data: RandomAccessCollection & RangeReplaceableCollection>(
navigationBarClass: AnyClass? = nil,
toolbarClass: AnyClass? = nil,
path: UIBinding<Data>,
root: () -> UIViewController
) where Data.Element: Hashable {
self.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)
super.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)
self._path = path.path
let root = root()
self.root = root
self.viewControllers = [root]
}

public convenience init(
public required init(
navigationBarClass: AnyClass? = nil,
toolbarClass: AnyClass? = nil,
path: UIBinding<UINavigationPath>,
root: () -> UIViewController
) {
self.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)
super.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)
self._path = path.elements
let root = root()
self.root = root
self.viewControllers = [root]
}


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

open override func viewDidLoad() {
super.viewDidLoad()

Expand Down