Created
June 28, 2018 14:47
-
-
Save tilltue/73c7e8fa416c881a496c950f92247851 to your computer and use it in GitHub Desktop.
Coordinator 코드
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
protocol ListOfPurchasesCoordinatorProtocol: Coordinator { | |
func presentInputView() | |
func presentModifyView(item: Item) | |
func presentCustomsInformationView(viewModel: ListOfPurchasesViewModel) | |
} | |
class ListOfPurchasesCoordinator: ListOfPurchasesCoordinatorProtocol { | |
weak var viewController: UIViewController? | |
let disposeBag = DisposeBag() | |
init(viewController: UIViewController) { | |
self.viewController = viewController | |
} | |
private func purchaseInputViewController() -> PurchaseInputViewController { | |
let purchaseInputViewController = Service.shared.container.resolve(PurchaseInputViewController.self)! | |
purchaseInputViewController.viewModel = Service.shared.container.resolve(PurchaseInputViewModel.self)! | |
purchaseInputViewController.purchaseInputCoordinator = PurchaseInputCoordinator(viewController: purchaseInputViewController) | |
purchaseInputViewController.viewModel.dismiss.subscribe(onNext: { [weak purchaseInputViewController] _ in | |
purchaseInputViewController?.dismiss(animated: true, completion: nil) | |
}).disposed(by: disposeBag) | |
purchaseInputViewController.modalTransitionStyle = .crossDissolve | |
return purchaseInputViewController | |
} | |
func presentInputView() { | |
Service.shared.container.register(PurchaseInputViewModel.self) { _ in PurchaseInputViewModel() } | |
let purchaseInputViewController = self.purchaseInputViewController() | |
if let latestSelectedCurrency = Currency(rawValue: Defaults[.latestSelectedCurrency]) { | |
purchaseInputViewController.viewModel.currency.accept(latestSelectedCurrency) | |
} | |
if let latestSelectedCategory = PurchaseCategory(rawValue: Defaults[.latestSelectedPurchaseCategory]) { | |
purchaseInputViewController.viewModel.category.accept(latestSelectedCategory) | |
} | |
self.viewController?.present(purchaseInputViewController, animated: true, completion: nil) | |
} | |
func presentModifyView(item: Item) { | |
let param = (id: item.id, currency: item.currency, category: item.category, price: item.price, createdAt: item.createdAt) | |
Service.shared.container.register(PurchaseInputViewModel.self) { _ in PurchaseInputViewModel(id: param.id, currency:param.currency, category: param.category, price: param.price, createdAt: param.createdAt) } | |
let purchaseInputViewController = self.purchaseInputViewController() | |
self.viewController?.present(purchaseInputViewController, animated: true, completion: nil) | |
} | |
func presentCustomsInformationView(viewModel: ListOfPurchasesViewModel) { | |
let customsInformationViewController = Service.shared.container.resolve(CustomsInformationViewController.self)! | |
customsInformationViewController.modalTransitionStyle = .crossDissolve | |
customsInformationViewController.viewModel = CustomsInformationViewModel(viewModel: viewModel) | |
customsInformationViewController.viewModel.dismisss.subscribe(onNext: { [weak customsInformationViewController] _ in | |
customsInformationViewController?.dismiss(animated: true, completion: nil) | |
}).disposed(by: disposeBag) | |
self.viewController?.present(customsInformationViewController, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment