-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
PledgePaymentMethodLoadingCell.swift
127 lines (96 loc) · 3.95 KB
/
PledgePaymentMethodLoadingCell.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
import Foundation
import Library
import Prelude
import UIKit
private enum Layout {
enum CardImageView {
static let minWidth: CGFloat = 40.0
}
}
final class PledgePaymentMethodLoadingCell: UITableViewCell, ValueCell {
// MARK: - Properties
private lazy var cardImagePlaceholder: UIView = { UIView(frame: .zero) }()
private lazy var contentStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var subtitlePlaceholder: UIView = { UIView(frame: .zero) }()
private lazy var subtitleStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var titlePlaceholder: UIView = { UIView(frame: .zero) }()
private lazy var titleStackView: UIStackView = { UIStackView(frame: .zero) }()
// MARK: - Lifecycle
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.configureViews()
self.setupConstraints()
self.startLoading()
}
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
self.layoutPlaceholderViews()
self.layoutGradientLayers()
}
private func layoutPlaceholderViews() {
self.cardImagePlaceholder.layoutIfNeeded()
self.subtitlePlaceholder.layoutIfNeeded()
self.titlePlaceholder.layoutIfNeeded()
_ = self.cardImagePlaceholder
|> roundedStyle(cornerRadius: Styles.grid(1))
_ = self.subtitlePlaceholder
|> roundedStyle(cornerRadius: self.subtitlePlaceholder.bounds.height / 2)
_ = self.titlePlaceholder
|> roundedStyle(cornerRadius: self.titlePlaceholder.bounds.height / 2)
}
override func bindStyles() {
super.bindStyles()
_ = self.rootStackView
|> \.spacing .~ Styles.grid(2)
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.insetsLayoutMarginsFromSafeArea .~ false
|> \.layoutMargins .~ .init(all: Styles.grid(2))
_ = self.contentStackView
|> \.axis .~ .vertical
|> \.distribution .~ .fillEqually
|> \.spacing .~ Styles.gridHalf(3)
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.insetsLayoutMarginsFromSafeArea .~ false
|> \.layoutMargins .~ .init(topBottom: Styles.grid(1))
_ = self.subtitleStackView
|> \.insetsLayoutMarginsFromSafeArea .~ false
_ = self.titleStackView
|> \.insetsLayoutMarginsFromSafeArea .~ false
}
func configureWith(value _: Void) {}
// MARK: - Subviews
private func configureViews() {
_ = (self.rootStackView, self)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()
_ = ([self.titlePlaceholder, UIView()], self.titleStackView)
|> ksr_addArrangedSubviewsToStackView()
_ = ([self.subtitlePlaceholder, UIView()], self.subtitleStackView)
|> ksr_addArrangedSubviewsToStackView()
_ = ([self.titleStackView, self.subtitleStackView], self.contentStackView)
|> ksr_addArrangedSubviewsToStackView()
_ = ([self.cardImagePlaceholder, self.contentStackView], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()
}
private func setupConstraints() {
let cardImageWidthConstraint = self.cardImagePlaceholder.widthAnchor
.constraint(equalToConstant: Layout.CardImageView.minWidth)
|> \.priority .~ .defaultHigh
NSLayoutConstraint.activate([
cardImageWidthConstraint,
self.cardImagePlaceholder.heightAnchor.constraint(equalTo: self.cardImagePlaceholder.widthAnchor),
self.titlePlaceholder.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5),
self.subtitlePlaceholder.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.4)
])
}
}
// MARK: - ShimmerLoading
extension PledgePaymentMethodLoadingCell: ShimmerLoading {
func shimmerViews() -> [UIView] {
return [self.cardImagePlaceholder, self.titlePlaceholder, self.subtitlePlaceholder]
}
}