Skip to content
This repository was archived by the owner on Oct 15, 2023. It is now read-only.

Commit c9312f5

Browse files
committed
Fix show indicator and error
1 parent 0429430 commit c9312f5

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

CleanArchitecture/Application/View-ViewModel/Scene/000 - TabBar/TabBarCoordinator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ final class TabBarCoordinator: Coordinate {
4444
let router = Router<InfoTarget>()
4545
let useCase = InfoNetwork(router: router)
4646
let coordinator = SettingsCoordinator()
47+
coordinator.viewController = controller
4748
let viewModel = SettingsViewModel(useCase: useCase, coordinator: coordinator)
4849
controller.viewModel = viewModel
4950
let navigationController = NavigationController(rootViewController: controller)

CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class SettingsViewController: ViewController, View {
2929
output.viewModels.drive(tableView.rx.items(cellIdentifier: DetailCell.identify, cellType: DetailCell.self)) { (_, viewModel, cell) in
3030
cell.viewModel = viewModel
3131
}.disposed(by: bag)
32+
output.indicator.drive().disposed(by: bag)
33+
output.error.drive().disposed(by: bag)
3234
}
3335
}
3436

CleanArchitecture/Application/View-ViewModel/Scene/002 - Settings/SettingsViewModel.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ final class SettingsViewModel: ViewModel {
2121
}
2222

2323
func transform(input: Input) -> Output {
24+
let indicator: RxIndicator = RxIndicator()
25+
let rxError: RxError = RxError()
2426
let viewModels: Driver<[DetailCellViewModel]> = input.loadTrigger
2527
.flatMapLatest { _ -> Driver<Info> in
26-
return self.useCase.about().emptyDriverIfError()
28+
return self.useCase.about().indicate(indicator).trackError(into: rxError).emptyDriverIfError()
2729
}
2830
.map { info -> [DetailCellViewModel] in
2931
return DetailCellViewModel.Kind.allCases.map { DetailCellViewModel(kind: $0, info: info) }
3032
}
31-
let output = Output(viewModels: viewModels)
33+
let error = rxError.asObservable().do(onNext: { (error) in
34+
self.coordinator?.showError(error)
35+
}).emptyDriverIfError()
36+
let output = Output(viewModels: viewModels, indicator: indicator.asObservable().emptyDriverIfError(), error: error)
3237
return output
3338
}
3439
}
@@ -41,6 +46,7 @@ extension SettingsViewModel {
4146

4247
struct Output {
4348
let viewModels: Driver<[DetailCellViewModel]>
44-
49+
let indicator: Driver<Bool>
50+
let error: Driver<Error>
4551
}
4652
}

CleanArchitecture/Application/View-ViewModel/Scene/003 - AddTask/AddTaskViewController.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,29 @@ final class AddTaskViewController: ViewController {
2424
setupBackground()
2525
setupNavi()
2626
setupTimePicker()
27-
setupTextField()
2827
}
2928

3029
override func bindViewModel() {
3130
super.bindViewModel()
32-
let save = saveButton.rx.tap.asDriver()
31+
let save = saveButton.rx.tap
32+
.do(onNext: { _ in
33+
self.view.endEditing(true)
34+
})
35+
.emptyDriverIfError()
3336
let cancel = cancelButton.rx.tap.asDriver()
3437
let time = timePicker.rx.date.asDriver()
3538
let name = nameTextField.rx.text.orEmpty.asDriver()
3639
let input = AddTaskViewModel.Input(cancelTrigger: cancel, saveTrigger: save, time: time, name: name)
3740
let output = viewModel.transform(input: input)
3841
output.cancel.drive().disposed(by: bag)
3942
output.save.drive().disposed(by: bag)
43+
nameTextField.rx.controlEvent(.editingDidEndOnExit)
44+
.do(onNext: { _ in
45+
self.view.endEditing(true)
46+
})
47+
.emptyDriverIfError()
48+
.drive()
49+
.disposed(by: bag)
4050
}
4151
}
4252

@@ -62,16 +72,4 @@ extension AddTaskViewController {
6272
timePicker.minimumDate = Date()
6373
timePicker.setValue(UIColor.white, forKey: "textColor")
6474
}
65-
66-
private func setupTextField() {
67-
nameTextField.delegate = self
68-
}
69-
}
70-
71-
// MARK: - UITextFieldDelegate
72-
extension AddTaskViewController: UITextFieldDelegate {
73-
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
74-
view.endEditing(true)
75-
return true
76-
}
7775
}

0 commit comments

Comments
 (0)