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
|
//
// RestorePurchasesView.swift
// MullvadVPN
//
// Created by Jon Petersson on 2024-08-15.
// Copyright © 2025 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.setAccessibilityIdentifier(.restorePurchasesButton)
label.attributedText = makeAttributedString()
label.adjustsFontForContentSizeCategory = true
label.isUserInteractionEnabled = true
label.numberOfLines = 0
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapRestoreButton)))
return label
}()
private lazy var infoButton: UIButton = {
let button = UIButton(type: .system)
button.adjustsImageSizeForAccessibilityContentSizeCategory = true
button.tintColor = .white
button.isExclusiveTouch = true
button.setImage(UIImage.Buttons.info, for: .normal)
button.tintColor = .white
button.addTarget(self, action: #selector(didTapInfoButton), for: .touchUpInside)
button.largeContentImageInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)
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", comment: "")
return NSAttributedString(
string: text,
attributes: [
.font: UIFont.mullvadMini,
.foregroundColor: UIColor.white,
.underlineStyle: NSUnderlineStyle.single.rawValue,
])
}
@objc private func didTapRestoreButton() {
restoreButtonAction?()
}
@objc private func didTapInfoButton() {
infoButtonAction?()
}
}
|