-
Notifications
You must be signed in to change notification settings - Fork 1
/
PRW.swift
91 lines (77 loc) · 3.38 KB
/
PRW.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
import GitHubUI
import Lists
import Palette
import SnapKit
import UIKit
final class DeploymentCheckRunCell: UITableViewCell, Bindable {
private static let iconSize = grid(5)
private let titleLabel = applying(UILabel(), compose(
Palette.numberOfLines(0),
Palette.textColor(Asset.textPrimary.color),
Palette.font(.preferredFont(forTextStyle: .body))
))
private let trailingTitleLabel = applying(UILabel(), compose(
Palette.numberOfLines(0),
Palette.textColor(Asset.textTertiary.color),
Palette.font(.preferredFont(forTextStyle: .callout))
))
private let leadingIconImageView = applying(UIImageView(), compose(
Palette.image(Asset.workflow24.image),
Palette.tintColor(Asset.iconPrimary.color)
))
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(leadingIconImageView)
contentView.addSubview(titleLabel)
contentView.addSubview(trailingTitleLabel)
leadingIconImageView.snp.makeConstraints { make in
make.width.height.equalTo(DeploymentCheckRunCell.iconSize)
make.leading.centerY.equalTo(contentView.layoutMarginsGuide)
}
titleLabel.snp.makeConstraints { make in
make.top.greaterThanOrEqualToSuperview().offset(grid(4))
make.bottom.lessThanOrEqualToSuperview().offset(grid(-4))
make.centerY.equalTo(leadingIconImageView)
make.leading.equalTo(leadingIconImageView.snp.trailing).offset(grid(4))
make.trailing.lessThanOrEqualTo(trailingTitleLabel.snp.leading)
}
trailingTitleLabel.snp.makeConstraints { make in
make.top.bottom.equalTo(contentView.layoutMarginsGuide)
make.trailing.equalTo(contentView.layoutMarginsGuide).offset(grid(-3))
}
let border = UIView()
border.backgroundColor = Asset.border.color
addSubview(border)
border.snp.makeConstraints { make in
make.height.equalTo(1.0 / UIScreen.main.scale)
make.top.trailing.equalToSuperview()
make.leading.equalTo(titleLabel.snp.leading)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private lazy var rotateAnimation: CABasicAnimation = {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat.pi * 2.0
rotateAnimation.duration = 1
rotateAnimation.repeatCount = .infinity
rotateAnimation.isRemovedOnCompletion = false
return rotateAnimation
}()
func bind(viewModel: CheckRunViewModel) {
titleLabel.text = viewModel.name
leadingIconImageView.tintColor = viewModel.iconColor
leadingIconImageView.image = viewModel.statusIcon
trailingTitleLabel.text = viewModel.statusLabel
trailingTitleLabel.textColor = viewModel.statusColor
if viewModel.isAnimating {
if leadingIconImageView.layer.animation(forKey: "transform.rotation") == nil {
leadingIconImageView.layer.add(rotateAnimation, forKey: "transform.rotation")
}
} else {
leadingIconImageView.layer.removeAnimation(forKey: "transform.rotation")
}
}
}