Skip to content

Commit 65e2c6f

Browse files
committed
Disable selectable text
1 parent 54302b4 commit 65e2c6f

File tree

1 file changed

+17
-41
lines changed

1 file changed

+17
-41
lines changed

ios/MullvadVPN/Views/InfoHeaderView.swift

+17-41
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,23 @@ class InfoHeaderView: UIView, UITextViewDelegate {
1414
/// Event handler invoked when user taps on the link.
1515
var onAbout: (() -> Void)?
1616

17-
private let textView = UITextView()
17+
private let infoLabel = UILabel()
1818
private let config: InfoHeaderConfig
1919

2020
init(config: InfoHeaderConfig) {
2121
self.config = config
2222

2323
super.init(frame: .zero)
2424

25-
textView.backgroundColor = .clear
26-
textView.dataDetectorTypes = .link
27-
textView.isSelectable = true
28-
textView.isEditable = false
29-
textView.isScrollEnabled = false
30-
textView.contentInset = .zero
31-
textView.textContainerInset = .zero
32-
textView.attributedText = makeAttributedString()
33-
textView.linkTextAttributes = defaultLinkAttributes
34-
textView.textContainer.lineFragmentPadding = 0
35-
textView.delegate = self
25+
infoLabel.backgroundColor = .clear
26+
infoLabel.attributedText = makeAttributedString()
27+
infoLabel.numberOfLines = 0
28+
infoLabel.accessibilityTraits = .link
3629

3730
directionalLayoutMargins = .zero
3831

3932
addSubviews()
33+
addTapGestureRecognizer()
4034
}
4135

4236
required init?(coder: NSCoder) {
@@ -49,21 +43,19 @@ class InfoHeaderView: UIView, UITextViewDelegate {
4943
]
5044

5145
private let defaultLinkAttributes: [NSAttributedString.Key: Any] = [
52-
.font: UIFont.systemFont(ofSize: 13),
46+
.font: UIFont.boldSystemFont(ofSize: 13),
5347
.foregroundColor: UIColor.ContentHeading.linkColor,
48+
.attachment: "#",
5449
]
5550

5651
private func makeAttributedString() -> NSAttributedString {
57-
var linkAttributes = defaultLinkAttributes
58-
linkAttributes[.link] = "#"
59-
6052
let paragraphStyle = NSMutableParagraphStyle()
6153
paragraphStyle.lineBreakMode = .byWordWrapping
6254

6355
let attributedString = NSMutableAttributedString()
6456
attributedString.append(NSAttributedString(string: config.body, attributes: defaultTextAttributes))
6557
attributedString.append(NSAttributedString(string: " ", attributes: defaultTextAttributes))
66-
attributedString.append(NSAttributedString(string: config.link, attributes: linkAttributes))
58+
attributedString.append(NSAttributedString(string: config.link, attributes: defaultLinkAttributes))
6759
attributedString.addAttribute(
6860
.paragraphStyle,
6961
value: paragraphStyle,
@@ -73,34 +65,18 @@ class InfoHeaderView: UIView, UITextViewDelegate {
7365
}
7466

7567
private func addSubviews() {
76-
addConstrainedSubviews([textView]) {
77-
textView.pinEdgesToSuperviewMargins()
68+
addConstrainedSubviews([infoLabel]) {
69+
infoLabel.pinEdgesToSuperviewMargins()
7870
}
7971
}
8072

81-
func textView(
82-
_ textView: UITextView,
83-
shouldInteractWith URL: URL,
84-
in characterRange: NSRange,
85-
interaction: UITextItemInteraction
86-
) -> Bool {
87-
onAbout?()
88-
return false
73+
private func addTapGestureRecognizer() {
74+
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTextViewTap))
75+
addGestureRecognizer(tapGesture)
8976
}
9077

91-
@available(iOS 17.0, *)
92-
func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem
93-
.MenuConfiguration? {
94-
return nil
95-
}
96-
97-
@available(iOS 17.0, *)
98-
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
99-
if case .link = textItem.content {
100-
return UIAction { [weak self] _ in
101-
self?.onAbout?()
102-
}
103-
}
104-
return nil
78+
@objc
79+
private func handleTextViewTap() {
80+
onAbout?()
10581
}
10682
}

0 commit comments

Comments
 (0)