Newer
Older
let statusLabel = UILabel()
let imageView = UIImageView()
let stackView = UIStackView()
let overlayView = OverlayView()
init() {
super.init(frame: .zero)
imageView.contentMode = .center
actionButton.setStyle(.brandColored)
statusLabel.numberOfLines = 0
statusLabel.textAlignment = .center
statusLabel.textColor = Asset.neutralWhite.color
statusLabel.font = Fonts.Mulish.regular.font(size: 14.0)
stackView.spacing = 15
stackView.axis = .vertical
stackView.addArrangedSubview(animationView)
stackView.addArrangedSubview(imageView)
stackView.addArrangedSubview(statusLabel)
stackView.addArrangedSubview(actionButton)
imageView.isHidden = true
actionButton.isHidden = true
animationView.isHidden = false
addSubview(overlayView)
addSubview(stackView)
setupConstraints()
}
required init?(coder: NSCoder) { nil }
setupTitle(for: status)
setupImageView(for: status)
setupActionButton(for: status)
setupCornerColors(for: status)
setupAnimationView(for: status)
}
private func setupTitle(for status: ScanningStatus) {
let title: String
title = Localized.Scan.Status.success
case .reading:
title = Localized.Scan.Status.reading
case .processing:
title = Localized.Scan.Status.processing
case .failed(let scanningError):
switch scanningError {
case .unknown(let content):
title = content
title = Localized.Scan.Error.cameraPermissionNeeded
let attString = NSMutableAttributedString(string: title)
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
paragraph.lineHeightMultiple = 1.35
attString.addAttribute(.paragraphStyle, value: paragraph)
attString.addAttribute(.foregroundColor, value: Asset.neutralWhite.color)
attString.addAttribute(.font, value: Fonts.Mulish.regular.font(size: 14.0) as Any)
attString.addAttribute(name: .foregroundColor, value: Asset.brandPrimary.color, betweenCharacters: "#")
}
statusLabel.attributedText = attString
}
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
136
137
138
139
140
141
142
143
144
145
146
147
private func setupImageView(for status: ScanningStatus) {
let image: UIImage?
switch status {
case .reading, .processing:
image = nil
case .success:
image = Asset.sharedSuccess.image
case .failed(_):
image = Asset.scanError.image
}
imageView.image = image
imageView.isHidden = image == nil
}
private func setupActionButton(for status: ScanningStatus) {
let buttonTitle: String?
switch status {
case .failed(.requestOpened):
buttonTitle = Localized.Scan.requests
case .failed(.alreadyFriends(_)):
buttonTitle = Localized.Scan.contact
case .failed(.cameraPermission):
buttonTitle = Localized.Scan.settings
case .reading, .processing, .success, .failed(.unknown(_)):
buttonTitle = nil
}
actionButton.setTitle(buttonTitle, for: .normal)
actionButton.isHidden = buttonTitle == nil
}
private func setupCornerColors(for status: ScanningStatus) {
let color: UIColor
switch status {
case .reading, .processing:
color = Asset.brandPrimary.color
case .success:
color = Asset.accentSuccess.color
case .failed(_):
color = Asset.accentDanger.color
}
overlayView.updateCornerColor(color)
}
private func setupAnimationView(for status: ScanningStatus) {
switch status {
case .reading, .processing:
animationView.isHidden = false
case .success, .failed(_):
animationView.isHidden = true
}
}
private func setupConstraints() {
overlayView.snp.makeConstraints {
$0.top.equalToSuperview()
$0.left.equalToSuperview()
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
}
stackView.snp.makeConstraints {
$0.left.equalToSuperview().offset(57)
$0.right.equalToSuperview().offset(-57)
$0.bottom.equalTo(safeAreaLayoutGuide).offset(-100)
}
}