Skip to content

Commit 565c708

Browse files
Allow the user to pick a HomeCoordinator instead of choosing them on its own
1 parent e696bf0 commit 565c708

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

XCoordinator-Example/Coordinators/AppCoordinator.swift

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
// Copyright © 2018 QuickBird Studios. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010
import XCoordinator
1111

1212
enum AppRoute: Route {
1313
case login
14-
case home
14+
case home(StrongRouter<HomeRoute>?)
1515
case newsDetail(News)
1616
}
1717

1818
class AppCoordinator: NavigationCoordinator<AppRoute> {
1919

20-
// MARK: Stored properties
21-
22-
private var homeRouteTriggerCount = 0
23-
2420
// MARK: Initialization
2521

2622
init() {
@@ -36,20 +32,37 @@ class AppCoordinator: NavigationCoordinator<AppRoute> {
3632
let viewModel = LoginViewModelImpl(router: unownedRouter)
3733
viewController.bind(to: viewModel)
3834
return .push(viewController)
39-
case .home:
40-
let presentables: [() -> Presentable] = [
41-
{ HomeTabCoordinator() },
42-
{ HomeSplitCoordinator() },
43-
{ HomePageCoordinator() }
44-
]
45-
let presentable = presentables[homeRouteTriggerCount % presentables.count]()
46-
homeRouteTriggerCount = (homeRouteTriggerCount + 1) % presentables.count
47-
return .presentFullScreen(presentable, animation: .fade)
35+
case let .home(router):
36+
if let router = router {
37+
return .presentFullScreen(router, animation: .fade)
38+
}
39+
let alert = UIAlertController(
40+
title: "How would you like to login?",
41+
message: "Please choose the type of coordinator used for the `Home` scene.",
42+
preferredStyle: .alert)
43+
alert.addAction(
44+
.init(title: "\(HomeTabCoordinator.self)", style: .default) { [unowned self] _ in
45+
self.trigger(.home(HomeTabCoordinator().strongRouter))
46+
}
47+
)
48+
alert.addAction(
49+
.init(title: "\(HomeSplitCoordinator.self)", style: .default) { [unowned self] _ in
50+
self.trigger(.home(HomeSplitCoordinator().strongRouter))
51+
}
52+
)
53+
alert.addAction(
54+
.init(title: "\(HomePageCoordinator.self)", style: .default) { [unowned self] _ in
55+
self.trigger(.home(HomePageCoordinator().strongRouter))
56+
}
57+
)
58+
return .present(alert)
4859
case .newsDetail(let news):
4960
return .multiple(
5061
.dismissAll(),
5162
.popToRoot(),
52-
deepLink(AppRoute.home, HomeRoute.news, NewsRoute.newsDetail(news))
63+
deepLink(AppRoute.home(HomePageCoordinator().strongRouter),
64+
HomeRoute.news,
65+
NewsRoute.newsDetail(news))
5366
)
5467
}
5568
}

XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LoginViewModelImpl: LoginViewModel, LoginViewModelInput, LoginViewModelOut
1919
// MARK: Actions
2020

2121
private lazy var loginAction = CocoaAction { [unowned self] in
22-
self.router.rx.trigger(.home)
22+
self.router.rx.trigger(.home(nil))
2323
}
2424

2525
// MARK: Stored properties

0 commit comments

Comments
 (0)