"Sources/AppCore/Models/HUDModel.swift" did not exist on "50a0d16c7789ff0cfd8d08a911df9be1ce847c90"
Newer
Older
import HUD
import UIKit
import Shared
import Models
import Combine
import DependencyInjection
public final class BackupController: UIViewController {
@Dependency private var hud: HUDType
private let viewModel = BackupViewModel.live()
private var cancellables = Set<AnyCancellable>()
public override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Asset.neutralWhite.color
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
setupNavigationBar()
setupBindings()
}
private func setupNavigationBar() {
navigationItem.backButtonTitle = ""
let title = UILabel()
title.text = Localized.Backup.header
title.textColor = Asset.neutralActive.color
title.font = Fonts.Mulish.semiBold.font(size: 18.0)
let back = UIButton.back()
back.addTarget(self, action: #selector(didTapBack), for: .touchUpInside)
navigationItem.leftBarButtonItem = UIBarButtonItem(
customView: UIStackView(arrangedSubviews: [back, title])
)
}
private func setupBindings() {
viewModel.state()
.receive(on: DispatchQueue.main)
.removeDuplicates()
.sink { [unowned self] in
hud.update(with: .none)
switch $0 {
case .setup:
contentViewController = BackupSetupController(viewModel.setupViewModel())
case .config:
contentViewController = BackupConfigController(viewModel.configViewModel())
}
}.store(in: &cancellables)
}
private var contentViewController: UIViewController? {
didSet {
guard contentViewController != oldValue else { return }
if let oldValue = oldValue {
oldValue.willMove(toParent: nil)
oldValue.view.removeFromSuperview()
oldValue.removeFromParent()
}
if let newValue = contentViewController {
addChild(newValue)
view.addSubview(newValue.view)
newValue.view.snp.makeConstraints { $0.edges.equalToSuperview() }
newValue.didMove(toParent: self)
}
}
}
@objc private func didTapBack() {
navigationController?.popViewController(animated: true)
}
}