Last active
December 22, 2022 16:08
-
-
Save aybarsyalcin/2c0a910feeeb5a08aa63e5c4c103aa66 to your computer and use it in GitHub Desktop.
Flow Coordinators - Part 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
final class HomeCoordinator: Coordinator, HomeCoordinatorOutput { | |
var finishHomeCoordinatorFlow: (() -> Void)? | |
var onAddressFlow: (() -> Void)? | |
private let factory: HomeModuleFactory | |
private let coordinatorFactory: CoordinatorFactory | |
private let router: Router | |
init(router: Router, | |
factory: HomeModuleFactory, | |
coordinatorFactory: CoordinatorFactory) { | |
self.router = router | |
self.factory = factory | |
self.coordinatorFactory = coordinatorFactory | |
} | |
override func start() { | |
showFlow() | |
} | |
// MARK: - Run current flow's controllers | |
private func showFlow() { | |
let homeOutput = factory.makeHomeCoordinatorOutput() | |
homeOutput.onBack = { [weak self] in | |
guard let self = self else { return } | |
self.finishHomeCoordinatorFlow?() | |
// Nothing beacuse this is root view. | |
} | |
homeOutput.onDetailPage = { [weak self] in | |
guard let self = self else { return } | |
self.showDetail() | |
} | |
homeOutput.onMyAddressesFlow = { [weak self] in | |
guard let self = self else { return } | |
self.onAddressFlow?() | |
} | |
router.setRootModule(homeOutput) | |
} | |
private func showDetail() { | |
let detailOutput = factory.makeDetailCoordinatorOutput() | |
detailOutput.onBack = { [weak self] in | |
guard let self = self else { return } | |
self.router.popModule() | |
} | |
detailOutput.onMyAddressesFlow = { [weak self] in | |
guard let self = self else { return } | |
self.onAddressFlow?() | |
} | |
router.push(detailOutput) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol HomeCoordinatorOutput: AnyObject { | |
var finishHomeCoordinatorFlow: (() -> Void)? { get set } | |
var onAddressFlow: (() -> Void)? { get set } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol HomeModuleFactory { | |
func makeHomeCoordinatorOutput() -> HomeCoordinatorView | |
func makeDetailCoordinatorOutput() -> DetailCoordinatorView | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment