@@ -14,29 +14,23 @@ class InfoHeaderView: UIView, UITextViewDelegate {
14
14
/// Event handler invoked when user taps on the link.
15
15
var onAbout : ( ( ) -> Void ) ?
16
16
17
- private let textView = UITextView ( )
17
+ private let infoLabel = UILabel ( )
18
18
private let config : InfoHeaderConfig
19
19
20
20
init ( config: InfoHeaderConfig ) {
21
21
self . config = config
22
22
23
23
super. init ( frame: . zero)
24
24
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
36
29
37
30
directionalLayoutMargins = . zero
38
31
39
32
addSubviews ( )
33
+ addTapGestureRecognizer ( )
40
34
}
41
35
42
36
required init ? ( coder: NSCoder ) {
@@ -49,21 +43,19 @@ class InfoHeaderView: UIView, UITextViewDelegate {
49
43
]
50
44
51
45
private let defaultLinkAttributes : [ NSAttributedString . Key : Any ] = [
52
- . font: UIFont . systemFont ( ofSize: 13 ) ,
46
+ . font: UIFont . boldSystemFont ( ofSize: 13 ) ,
53
47
. foregroundColor: UIColor . ContentHeading. linkColor,
48
+ . attachment: " # " ,
54
49
]
55
50
56
51
private func makeAttributedString( ) -> NSAttributedString {
57
- var linkAttributes = defaultLinkAttributes
58
- linkAttributes [ . link] = " # "
59
-
60
52
let paragraphStyle = NSMutableParagraphStyle ( )
61
53
paragraphStyle. lineBreakMode = . byWordWrapping
62
54
63
55
let attributedString = NSMutableAttributedString ( )
64
56
attributedString. append ( NSAttributedString ( string: config. body, attributes: defaultTextAttributes) )
65
57
attributedString. append ( NSAttributedString ( string: " " , attributes: defaultTextAttributes) )
66
- attributedString. append ( NSAttributedString ( string: config. link, attributes: linkAttributes ) )
58
+ attributedString. append ( NSAttributedString ( string: config. link, attributes: defaultLinkAttributes ) )
67
59
attributedString. addAttribute (
68
60
. paragraphStyle,
69
61
value: paragraphStyle,
@@ -73,34 +65,18 @@ class InfoHeaderView: UIView, UITextViewDelegate {
73
65
}
74
66
75
67
private func addSubviews( ) {
76
- addConstrainedSubviews ( [ textView ] ) {
77
- textView . pinEdgesToSuperviewMargins ( )
68
+ addConstrainedSubviews ( [ infoLabel ] ) {
69
+ infoLabel . pinEdgesToSuperviewMargins ( )
78
70
}
79
71
}
80
72
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)
89
76
}
90
77
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 ? ( )
105
81
}
106
82
}
0 commit comments