Add links/mentions/hashtag to VoiceOver rotor in timelines

Closes #231
This commit is contained in:
Shadowfacts 2022-11-28 18:51:04 -05:00
parent c01bc4d840
commit 4f28fec62a
2 changed files with 43 additions and 1 deletions

View File

@ -395,6 +395,27 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
return true
}
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
guard let text = contentTextView.attributedText else {
return nil
}
var actions: [UIAccessibilityCustomAction] = []
text.enumerateAttribute(.link, in: NSRange(location: 0, length: text.length)) { value, range, stop in
guard let value = value as? URL else {
return
}
let text = text.attributedSubstring(from: range).string
actions.append(UIAccessibilityCustomAction(name: text) { [unowned self] _ in
self.contentTextView.handleLinkTapped(url: value, text: text)
return true
})
}
return actions
}
set {}
}
// MARK: Configure UI
func updateUI(statusID: String, state: StatusState) {

View File

@ -307,7 +307,28 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
}
return true
}
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
guard let text = contentTextView.attributedText else {
return nil
}
var actions: [UIAccessibilityCustomAction] = []
text.enumerateAttribute(.link, in: NSRange(location: 0, length: text.length)) { value, range, stop in
guard let value = value as? URL else {
return
}
let text = text.attributedSubstring(from: range).string
actions.append(UIAccessibilityCustomAction(name: text) { [unowned self] _ in
self.contentTextView.handleLinkTapped(url: value, text: text)
return true
})
}
return actions
}
set {}
}
}
extension TimelineStatusTableViewCell: SelectableTableViewCell {