diff --git a/CleanArchitecture/Application/View-ViewModel/Scene/000 - TabBar/TabBarCoordinator.swift b/CleanArchitecture/Application/View-ViewModel/Scene/000 - TabBar/TabBarCoordinator.swift index 60b3303..2296709 100644 --- a/CleanArchitecture/Application/View-ViewModel/Scene/000 - TabBar/TabBarCoordinator.swift +++ b/CleanArchitecture/Application/View-ViewModel/Scene/000 - TabBar/TabBarCoordinator.swift @@ -44,6 +44,7 @@ final class TabBarCoordinator: Coordinate { let router = Router() let useCase = InfoNetwork(router: router) let coordinator = SettingsCoordinator() + coordinator.viewController = controller let viewModel = SettingsViewModel(useCase: useCase, coordinator: coordinator) controller.viewModel = viewModel let navigationController = NavigationController(rootViewController: controller) diff --git a/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewController.swift b/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewController.swift index 6b380fa..951a027 100644 --- a/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewController.swift +++ b/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewController.swift @@ -29,6 +29,8 @@ final class SettingsViewController: ViewController, View { output.viewModels.drive(tableView.rx.items(cellIdentifier: DetailCell.identify, cellType: DetailCell.self)) { (_, viewModel, cell) in cell.viewModel = viewModel }.disposed(by: bag) + output.indicator.drive().disposed(by: bag) + output.error.drive().disposed(by: bag) } } diff --git a/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewModel.swift b/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewModel.swift index 28a8717..b716633 100644 --- a/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewModel.swift +++ b/CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewModel.swift @@ -21,14 +21,19 @@ final class SettingsViewModel: ViewModel { } func transform(input: Input) -> Output { + let indicator: RxIndicator = RxIndicator() + let rxError: RxError = RxError() let viewModels: Driver<[DetailCellViewModel]> = input.loadTrigger .flatMapLatest { _ -> Driver in - return self.useCase.about().emptyDriverIfError() + return self.useCase.about().indicate(indicator).trackError(into: rxError).emptyDriverIfError() } .map { info -> [DetailCellViewModel] in return DetailCellViewModel.Kind.allCases.map { DetailCellViewModel(kind: $0, info: info) } } - let output = Output(viewModels: viewModels) + let error = rxError.asObservable().do(onNext: { (error) in + self.coordinator?.showError(error) + }).emptyDriverIfError() + let output = Output(viewModels: viewModels, indicator: indicator.asObservable().emptyDriverIfError(), error: error) return output } } @@ -41,6 +46,7 @@ extension SettingsViewModel { struct Output { let viewModels: Driver<[DetailCellViewModel]> - + let indicator: Driver + let error: Driver } } diff --git a/CleanArchitecture/Application/View-ViewModel/Scene/003 - AddTask/AddTaskViewController.swift b/CleanArchitecture/Application/View-ViewModel/Scene/003 - AddTask/AddTaskViewController.swift index f39370e..fcc33e1 100644 --- a/CleanArchitecture/Application/View-ViewModel/Scene/003 - AddTask/AddTaskViewController.swift +++ b/CleanArchitecture/Application/View-ViewModel/Scene/003 - AddTask/AddTaskViewController.swift @@ -24,12 +24,15 @@ final class AddTaskViewController: ViewController { setupBackground() setupNavi() setupTimePicker() - setupTextField() } override func bindViewModel() { super.bindViewModel() - let save = saveButton.rx.tap.asDriver() + let save = saveButton.rx.tap + .do(onNext: { _ in + self.view.endEditing(true) + }) + .emptyDriverIfError() let cancel = cancelButton.rx.tap.asDriver() let time = timePicker.rx.date.asDriver() let name = nameTextField.rx.text.orEmpty.asDriver() @@ -37,6 +40,13 @@ final class AddTaskViewController: ViewController { let output = viewModel.transform(input: input) output.cancel.drive().disposed(by: bag) output.save.drive().disposed(by: bag) + nameTextField.rx.controlEvent(.editingDidEndOnExit) + .do(onNext: { _ in + self.view.endEditing(true) + }) + .emptyDriverIfError() + .drive() + .disposed(by: bag) } } @@ -62,16 +72,4 @@ extension AddTaskViewController { timePicker.minimumDate = Date() timePicker.setValue(UIColor.white, forKey: "textColor") } - - private func setupTextField() { - nameTextField.delegate = self - } -} - -// MARK: - UITextFieldDelegate -extension AddTaskViewController: UITextFieldDelegate { - func textFieldShouldReturn(_ textField: UITextField) -> Bool { - view.endEditing(true) - return true - } }