summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2024-12-04 07:16:39 +0100
committerBug Magnet <marco.nikic@mullvad.net>2024-12-04 07:16:39 +0100
commitd44108b9e3fb403889490ccc173e085fd766e03e (patch)
treeb277cc7ee59e483950440d354af13646e4f7f91d
parent54302b40648f5d8974f2ec6dc772f5af4e9d4bb9 (diff)
parent65e2c6f26527b40426e372c1befd9a81842d5072 (diff)
downloadmullvadvpn-d44108b9e3fb403889490ccc173e085fd766e03e.tar.xz
mullvadvpn-d44108b9e3fb403889490ccc173e085fd766e03e.zip
Merge branch 'disable-selectable-text-in-formatted-textview-ios-930'
-rw-r--r--ios/MullvadVPN/Views/InfoHeaderView.swift58
1 files changed, 17 insertions, 41 deletions
diff --git a/ios/MullvadVPN/Views/InfoHeaderView.swift b/ios/MullvadVPN/Views/InfoHeaderView.swift
index 67564bc312..4a5357108a 100644
--- a/ios/MullvadVPN/Views/InfoHeaderView.swift
+++ b/ios/MullvadVPN/Views/InfoHeaderView.swift
@@ -14,7 +14,7 @@ class InfoHeaderView: UIView, UITextViewDelegate {
/// Event handler invoked when user taps on the link.
var onAbout: (() -> Void)?
- private let textView = UITextView()
+ private let infoLabel = UILabel()
private let config: InfoHeaderConfig
init(config: InfoHeaderConfig) {
@@ -22,21 +22,15 @@ class InfoHeaderView: UIView, UITextViewDelegate {
super.init(frame: .zero)
- textView.backgroundColor = .clear
- textView.dataDetectorTypes = .link
- textView.isSelectable = true
- textView.isEditable = false
- textView.isScrollEnabled = false
- textView.contentInset = .zero
- textView.textContainerInset = .zero
- textView.attributedText = makeAttributedString()
- textView.linkTextAttributes = defaultLinkAttributes
- textView.textContainer.lineFragmentPadding = 0
- textView.delegate = self
+ infoLabel.backgroundColor = .clear
+ infoLabel.attributedText = makeAttributedString()
+ infoLabel.numberOfLines = 0
+ infoLabel.accessibilityTraits = .link
directionalLayoutMargins = .zero
addSubviews()
+ addTapGestureRecognizer()
}
required init?(coder: NSCoder) {
@@ -49,21 +43,19 @@ class InfoHeaderView: UIView, UITextViewDelegate {
]
private let defaultLinkAttributes: [NSAttributedString.Key: Any] = [
- .font: UIFont.systemFont(ofSize: 13),
+ .font: UIFont.boldSystemFont(ofSize: 13),
.foregroundColor: UIColor.ContentHeading.linkColor,
+ .attachment: "#",
]
private func makeAttributedString() -> NSAttributedString {
- var linkAttributes = defaultLinkAttributes
- linkAttributes[.link] = "#"
-
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byWordWrapping
let attributedString = NSMutableAttributedString()
attributedString.append(NSAttributedString(string: config.body, attributes: defaultTextAttributes))
attributedString.append(NSAttributedString(string: " ", attributes: defaultTextAttributes))
- attributedString.append(NSAttributedString(string: config.link, attributes: linkAttributes))
+ attributedString.append(NSAttributedString(string: config.link, attributes: defaultLinkAttributes))
attributedString.addAttribute(
.paragraphStyle,
value: paragraphStyle,
@@ -73,34 +65,18 @@ class InfoHeaderView: UIView, UITextViewDelegate {
}
private func addSubviews() {
- addConstrainedSubviews([textView]) {
- textView.pinEdgesToSuperviewMargins()
+ addConstrainedSubviews([infoLabel]) {
+ infoLabel.pinEdgesToSuperviewMargins()
}
}
- func textView(
- _ textView: UITextView,
- shouldInteractWith URL: URL,
- in characterRange: NSRange,
- interaction: UITextItemInteraction
- ) -> Bool {
- onAbout?()
- return false
+ private func addTapGestureRecognizer() {
+ let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTextViewTap))
+ addGestureRecognizer(tapGesture)
}
- @available(iOS 17.0, *)
- func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem
- .MenuConfiguration? {
- return nil
- }
-
- @available(iOS 17.0, *)
- func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
- if case .link = textItem.content {
- return UIAction { [weak self] _ in
- self?.onAbout?()
- }
- }
- return nil
+ @objc
+ private func handleTextViewTap() {
+ onAbout?()
}
}