Created
January 14, 2020 15:01
-
-
Save zafarivaev/270181afdc77778d3554b45a89f4f22a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RxSwift | |
import ReactiveCoordinator | |
enum ChooseCountryCoordinationResult { | |
case country(String) | |
case cancel | |
} | |
class ChooseCountryCoordinator: ReactiveCoordinator<ChooseCountryCoordinationResult> { | |
private let rootViewController: UIViewController | |
init(rootViewController: UIViewController) { | |
self.rootViewController = rootViewController | |
} | |
override func start() -> Observable<CoordinationResult> { | |
let viewController = ChooseCountryViewController() | |
let navigationController = UINavigationController(rootViewController: viewController) | |
let viewModel = ChooseCountryViewModel() | |
viewController.viewModel = viewModel | |
let country = viewModel.selectedCountry.map { CoordinationResult.country($0) } | |
let cancel = viewModel.didClose.map { _ in | |
CoordinationResult.cancel | |
} | |
rootViewController.present(navigationController, animated: true, completion: nil) | |
return Observable.merge(country, cancel) | |
.take(1) | |
.do(onNext: { _ in | |
viewController.dismiss(animated: true, completion: nil) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment