-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathPaywallView.swift
171 lines (143 loc) · 6.26 KB
/
PaywallView.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// AdvancedWallView.swift
// LockdownSandbox
//
// Created by Алишер Ахметжанов on 28.04.2023.
//
import UIKit
import Foundation
final class PaywallView: UIView {
//MARK: Properties
private let model: PaywallViewModel
var isSelected: Bool = false
lazy var scrollView: UIScrollView = {
let view = UIScrollView()
view.isScrollEnabled = true
view.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 17, right: 0)
return view
}()
lazy var contentView: UIView = {
let view = UIView()
view.anchors.height.equal(400)
return view
}()
lazy var headlineLabel: PaywallDescriptionLabel = {
let label = PaywallDescriptionLabel()
label.titleLabel.text = model.title
label.subtitleLabel.text = model.subtitle
return label
}()
private lazy var bulletsStackView: UIStackView = {
let stackView = UIStackView()
stackView.addArrangedSubview(headlineLabel)
model.bulletPoints.forEach {
stackView.addArrangedSubview(bulletView(forTitle: $0))
}
stackView.axis = .vertical
stackView.spacing = 8
return stackView
}()
lazy var trialDescriptionLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = fontRegular12
label.textColor = .white
label.textAlignment = .center
let anualPrice = VPNSubscription.getProductIdPrice(productId: model.annualProductId)
let monthlyPrice = VPNSubscription.getProductIdPriceMonthly(productId: model.annualProductId)
let trialDuation = VPNSubscription.trialDuration(productId: model.annualProductId) ?? ""
let title = trialDuation + " " + NSLocalizedString("free trial", comment: "") + "," + " then \(anualPrice) (\(monthlyPrice)/mo)"
label.text = title
return label
}()
lazy var bottomProduct: ProductButton = {
let descriptionLabelPrice1 = VPNSubscription.getProductIdPrice(productId: model.mounthProductId)
let trialDuation = VPNSubscription.trialDuration(productId: model.annualProductId) ?? ""
let title = trialDuation + " " + NSLocalizedString("trial", comment: "")
var descriptionTitle = trialDuation.isEmpty ? "" : NSLocalizedString("then", comment: "") + " "
descriptionTitle += descriptionLabelPrice1 + NSLocalizedString("/year", comment: "")
let button = ProductButton(title: "Monthly", subtitle: descriptionLabelPrice1, toHighlight: descriptionLabelPrice1)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
lazy var topProduct: ProductButton = {
let annyalPrice = VPNSubscription.getProductIdPrice(productId: model.annualProductId)
let monthlyPrice = VPNSubscription.getProductIdPriceMonthly(productId: model.annualProductId)
var descriptionTitle = "\(annyalPrice)" + " (\(monthlyPrice)/mo)"
let button = ProductButton(title: "Yearly", subtitle: descriptionTitle, toHighlight: annyalPrice, isSelected: true)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
func updateCTATitle(for productID: String) {
let hasTrial = VPNSubscription.trialDuration(productId: productID) != nil
let title = hasTrial ? "Start for Free" : "Continue"
actionButton.setTitle(title, for: .normal)
}
lazy var actionButton: UIButton = {
let button = UIButton(type: .system)
button.tintColor = .white
button.backgroundColor = .tunnelsBlue
button.layer.cornerRadius = 28
let title = "Start for Free"
button.titleLabel?.font = fontSemiBold17
button.setTitle(title, for: .normal)
return button
}()
//MARK: Initialization
init(model: PaywallViewModel) {
self.model = model
super.init(frame: .zero)
configureUI()
}
override init(frame: CGRect) {
model = .empty()
super.init(frame: frame)
configureUI()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//MARK: ConfigureUI
private func configureUI() {
addSubview(actionButton)
actionButton.anchors.bottom.pin()
actionButton.anchors.leading.marginsPin()
actionButton.anchors.trailing.marginsPin()
actionButton.anchors.height.equal(58)
addSubview(trialDescriptionLabel)
trialDescriptionLabel.anchors.leading.marginsPin()
trialDescriptionLabel.anchors.trailing.marginsPin()
trialDescriptionLabel.anchors.bottom.spacing(10, to: actionButton.anchors.top)
addSubview(bottomProduct)
bottomProduct.anchors.bottom.spacing(35, to: actionButton.anchors.top)
bottomProduct.anchors.leading.marginsPin()
bottomProduct.anchors.trailing.marginsPin()
bottomProduct.anchors.height.equal(60)
addSubview(topProduct)
topProduct.anchors.bottom.spacing(16, to: bottomProduct.anchors.top)
topProduct.anchors.leading.marginsPin()
topProduct.anchors.trailing.marginsPin()
topProduct.anchors.height.equal(60)
addSubview(scrollView)
scrollView.anchors.top.pin()
scrollView.anchors.leading.pin(inset: 16)
scrollView.anchors.trailing.pin()
scrollView.showsVerticalScrollIndicator = false
scrollView.anchors.bottom.spacing(8, to: topProduct.anchors.top)
scrollView.addSubview(contentView)
contentView.anchors.top.pin()
contentView.anchors.centerX.align()
contentView.anchors.width.equal(scrollView.anchors.width)
contentView.anchors.bottom.pin()
contentView.addSubview(bulletsStackView)
bulletsStackView.anchors.top.marginsPin()
bulletsStackView.anchors.leading.marginsPin()
bulletsStackView.anchors.trailing.marginsPin()
}
private func bulletView(forTitle title: String) -> BulletView {
let view = BulletView()
view.configure(with: BulletViewModel(image: UIImage(named: "Checkbox")!, title: title))
return view
}
}