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
|
//
// AccountContentView.swift
// MullvadVPN
//
// Created by pronebird on 08/07/2021.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import UIKit
class AccountContentView: UIView {
let purchaseButton: InAppPurchaseButton = {
let button = InAppPurchaseButton()
button.setAccessibilityIdentifier(.purchaseButton)
button.setTitle(NSLocalizedString("Add time", comment: ""), for: .normal)
return button
}()
let storeKit2PurchaseButton: AppButton = {
let button = AppButton(style: .success)
button.setTitle(NSLocalizedString("Make a purchase with StoreKit2", comment: ""), for: .normal)
return button
}()
let storeKit2RefundButton: AppButton = {
let button = AppButton(style: .success)
button.setTitle(NSLocalizedString("Refund last purchase with StoreKit2", comment: ""), for: .normal)
return button
}()
let redeemVoucherButton: AppButton = {
let button = AppButton(style: .success)
button.setAccessibilityIdentifier(.redeemVoucherButton)
button.setTitle(NSLocalizedString("Redeem voucher", comment: ""), for: .normal)
return button
}()
let logoutButton: AppButton = {
let button = AppButton(style: .danger)
button.setAccessibilityIdentifier(.logoutButton)
button.setTitle(NSLocalizedString("Log out", comment: ""), for: .normal)
return button
}()
let deleteButton: AppButton = {
let button = AppButton(style: .danger)
button.setAccessibilityIdentifier(.deleteButton)
button.setTitle(NSLocalizedString("Delete account", comment: ""), for: .normal)
return button
}()
let accountDeviceRow: AccountDeviceRow = {
AccountDeviceRow()
}()
let accountTokenRowView: AccountNumberRow = {
AccountNumberRow()
}()
let accountExpiryRowView: AccountExpiryRow = {
AccountExpiryRow()
}()
let restorePurchasesView: RestorePurchasesView = {
RestorePurchasesView()
}()
lazy var contentStackView: UIStackView = {
let stackView =
UIStackView(arrangedSubviews: [
accountDeviceRow,
accountTokenRowView,
accountExpiryRowView,
restorePurchasesView,
])
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding24
stackView.setCustomSpacing(UIMetrics.padding8, after: accountExpiryRowView)
return stackView
}()
lazy var buttonStackView: UIStackView = {
var arrangedSubviews = [UIView]()
#if DEBUG
arrangedSubviews.append(redeemVoucherButton)
arrangedSubviews.append(storeKit2PurchaseButton)
arrangedSubviews.append(storeKit2RefundButton)
#endif
arrangedSubviews.append(contentsOf: [
purchaseButton,
logoutButton,
deleteButton,
])
arrangedSubviews.forEach { $0.isExclusiveTouch = true }
let stackView = UIStackView(arrangedSubviews: arrangedSubviews)
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding16
return stackView
}()
override init(frame: CGRect) {
super.init(frame: frame)
setAccessibilityIdentifier(.accountView)
addScrollView()
}
private func addScrollView() {
let scrollView = UIScrollView()
let contentView = UIView()
addConstrainedSubviews([scrollView]) {
scrollView.pinEdgesToSuperviewMargins()
}
scrollView.addConstrainedSubviews([contentView]) {
contentView.pinEdgesToSuperview()
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor)
contentView.heightAnchor.constraint(greaterThanOrEqualTo: scrollView.frameLayoutGuide.heightAnchor)
}
let spacer = UIView()
contentView.addConstrainedSubviews([contentStackView, spacer, buttonStackView]) {
contentStackView.pinEdgesToSuperviewMargins(.all().excluding(.bottom))
spacer.pinEdgesToSuperviewMargins(.all().excluding(.top).excluding(.bottom))
buttonStackView.pinEdgesToSuperviewMargins(.all().excluding(.top))
spacer.bottomAnchor.constraint(equalTo: buttonStackView.topAnchor)
spacer.topAnchor.constraint(
equalTo: contentStackView.bottomAnchor,
constant: UIMetrics.TableView.sectionSpacing
)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
|