-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathRestorePurchasesView.swift
82 lines (69 loc) · 2.41 KB
/
RestorePurchasesView.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
//
// RestorePurchasesView.swift
// MullvadVPN
//
// Created by Jon Petersson on 2024-08-15.
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
//
import UIKit
class RestorePurchasesView: UIView {
var restoreButtonAction: (() -> Void)?
var infoButtonAction: (() -> Void)?
private lazy var contentView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
restoreButton,
infoButton,
UIView(), // Pushes the other views to the left.
])
stackView.spacing = UIMetrics.padding8
return stackView
}()
private lazy var restoreButton: UILabel = {
let label = UILabel()
label.accessibilityIdentifier = .restorePurchasesButton
label.attributedText = makeAttributedString()
label.isUserInteractionEnabled = true
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapRestoreButton)))
return label
}()
private lazy var infoButton: UIButton = {
let button = IncreasedHitButton(type: .custom)
button.setImage(UIImage(resource: .iconInfo), for: .normal)
button.tintColor = .white
button.addTarget(self, action: #selector(didTapInfoButton), for: .touchUpInside)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
addConstrainedSubviews([contentView]) {
contentView.pinEdgesToSuperview()
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setButtons(enabled: Bool) {
restoreButton.isUserInteractionEnabled = enabled
restoreButton.alpha = enabled ? 1 : 0.5
infoButton.isEnabled = enabled
}
private func makeAttributedString() -> NSAttributedString {
let text = NSLocalizedString(
"RESTORE_PURCHASES_BUTTON_TITLE",
tableName: "Account",
value: "Restore purchases",
comment: ""
)
return NSAttributedString(string: text, attributes: [
.font: UIFont.systemFont(ofSize: 13, weight: .semibold),
.foregroundColor: UIColor.white,
.underlineStyle: NSUnderlineStyle.single.rawValue,
])
}
@objc private func didTapRestoreButton() {
restoreButtonAction?()
}
@objc private func didTapInfoButton() {
infoButtonAction?()
}
}