Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import HUD
import Popup
import Theme
import UIKit
import Shared
import Combine
import DependencyInjection
import ScrollViewController
final class OnboardingUsernameController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
lazy private var screenView = OnboardingUsernameView()
lazy private var scrollViewController = ScrollViewController()
private var cancellables = Set<AnyCancellable>()
private let viewModel: OnboardingUsernameViewModel!
private var popupCancellables = Set<AnyCancellable>()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
statusBarController.style.send(.darkContent)
navigationController?.navigationBar.customize(translucent: true)
}
init(_ ndf: String) {
self.viewModel = OnboardingUsernameViewModel(ndf: ndf)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) { nil }
override func viewDidLoad() {
super.viewDidLoad()
setupScrollView()
setupBindings()
screenView.didTapInfo = { [weak self] in
self?.presentInfo(
title: Localized.Onboarding.Username.Info.title,
subtitle: Localized.Onboarding.Username.Info.subtitle,
urlString: "https://links.xx.network/ud"
)
}
}
private func setupScrollView() {
scrollViewController.scrollView.backgroundColor = .white
addChild(scrollViewController)
view.addSubview(scrollViewController.view)
scrollViewController.view.snp.makeConstraints { $0.edges.equalToSuperview() }
scrollViewController.didMove(toParent: self)
scrollViewController.contentView = screenView
}
private func setupBindings() {
viewModel.hud
.receive(on: DispatchQueue.main)
.sink { [hud] in hud.update(with: $0) }
.store(in: &cancellables)
screenView.inputField.textPublisher
.removeDuplicates()
.compactMap { $0 }
.sink { [unowned self] in viewModel.didInput($0) }
.store(in: &cancellables)
screenView.inputField.returnPublisher
.sink { [unowned self] in
if screenView.nextButton.isEnabled {
viewModel.didTapRegister()
} else {
screenView.inputField.endEditing(true)
}
}.store(in: &cancellables)
screenView.nextButton.publisher(for: .touchUpInside)
.sink { [unowned self] in viewModel.didTapRegister() }
.store(in: &cancellables)
viewModel.greenPublisher
.receive(on: DispatchQueue.main)
.sink { [unowned self] in coordinator.toWelcome(from: self) }
.store(in: &cancellables)
viewModel.state
.map(\.status)
.removeDuplicates()
.receive(on: DispatchQueue.main)
.sink { [unowned self] in screenView.update(status: $0) }
.store(in: &cancellables)
}
private func presentInfo(
title: String,
subtitle: String,
urlString: String = ""
) {
let actionButton = CapsuleButton()
actionButton.set(
style: .seeThrough,
title: Localized.Settings.InfoPopUp.action
)
let popup = BottomPopup(with: [
PopupLabel(
font: Fonts.Mulish.bold.font(size: 26.0),
text: title,
color: Asset.neutralActive.color,
alignment: .left,
spacingAfter: 19
),
PopupLinkText(
text: subtitle,
urlString: urlString,
spacingAfter: 37
),
PopupStackView(views: [actionButton, FlexibleSpace()])
])
actionButton.publisher(for: .touchUpInside)
.receive(on: DispatchQueue.main)
.sink {
popup.dismiss(animated: true) { [weak self] in
guard let self = self else { return }
self.popupCancellables.removeAll()
}
}.store(in: &popupCancellables)
coordinator.toPopup(popup, from: self)
}
}