-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework the Restore Purchases button to decrease user confusion
- Loading branch information
Jon Petersson
committed
Aug 15, 2024
1 parent
92eab6f
commit 751c334
Showing
6 changed files
with
173 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
ios/MullvadVPN/View controllers/Account/RestorePurchasesView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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?() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters