-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
CategorySelectionHeaderView.swift
135 lines (107 loc) · 3.81 KB
/
CategorySelectionHeaderView.swift
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 Library
import Prelude
import UIKit
final class CategorySelectionHeaderView: UIView {
// MARK: - Properties
private lazy var imageView = { UIImageView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()
private lazy var rootStackView = {
UIStackView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()
private lazy var stepLabel = { UILabel(frame: .zero) }()
private lazy var subtitleLabel = { UILabel(frame: .zero) }()
private lazy var titleLabel = { UILabel(frame: .zero) }()
private let viewModel: CategorySelectionHeaderViewModelType = CategorySelectionHeaderViewModel()
override init(frame: CGRect) {
super.init(frame: frame)
self.setupViews()
self.bindStyles()
self.bindViewModel()
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func configure(with context: CategorySelectionOnboardingHeaderViewContext) {
self.viewModel.inputs.configure(with: context)
}
override func bindStyles() {
super.bindStyles()
_ = self
|> \.clipsToBounds .~ true
|> \.backgroundColor .~ UIColor.ksr_trust_700
_ = self.rootStackView
|> rootStackViewStyle
_ = self.titleLabel
|> titleLabelStyle
_ = self.subtitleLabel
|> subtitleLabelStyle
_ = self.stepLabel
|> stepLabelStyle
_ = self.imageView
|> imageViewStyle
}
private func setupViews() {
_ = (self.rootStackView, self)
|> ksr_addSubviewToParent()
_ = ([self.stepLabel, self.titleLabel, self.subtitleLabel], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()
_ = (self.imageView, self)
|> ksr_addSubviewToParent()
NSLayoutConstraint.activate([
self.rootStackView.leftAnchor.constraint(equalTo: self.leftAnchor),
self.rootStackView.rightAnchor.constraint(equalTo: self.rightAnchor),
self.rootStackView.topAnchor.constraint(equalTo: self.topAnchor),
self.imageView.leftAnchor.constraint(equalTo: self.leftAnchor),
self.imageView.rightAnchor.constraint(equalTo: self.rightAnchor),
self.imageView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
self.imageView.topAnchor.constraint(equalTo: self.rootStackView.bottomAnchor)
])
_ = (self.stepLabel, self.rootStackView)
|> ksr_setCustomSpacing(Styles.grid(1))
}
override func bindViewModel() {
super.bindViewModel()
self.stepLabel.rac.text = self.viewModel.outputs.stepLabelText
self.subtitleLabel.rac.text = self.viewModel.outputs.subtitleLabelText
self.titleLabel.rac.text = self.viewModel.outputs.titleLabelText
}
}
// MARK: - Styles
private let rootStackViewStyle: StackViewStyle = { stackView in
stackView
|> verticalStackViewStyle
|> \.distribution .~ .fill
|> \.alignment .~ .fill
|> \.spacing .~ Styles.grid(2)
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.layoutMargins .~ .init(topBottom: Styles.grid(0), leftRight: Styles.grid(3))
}
private let titleLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_title3().bolded
|> \.textColor .~ .ksr_white
|> \.lineBreakMode .~ .byTruncatingTail
|> \.numberOfLines .~ 3
}
private let subtitleLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_subhead()
|> \.textColor .~ .ksr_white
|> \.lineBreakMode .~ .byTruncatingTail
|> \.numberOfLines .~ 2
}
private let stepLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_footnote()
|> \.textColor .~ .ksr_white
|> \.lineBreakMode .~ .byTruncatingTail
|> \.numberOfLines .~ 1
}
private let imageViewStyle: ImageViewStyle = { imageView in
imageView
|> UIImageView.lens.contentMode .~ .scaleAspectFill
|> UIImageView.lens.image .~ image(named: "shapes")
}