From 4f28fec62a21f93e8738c20e4c1616db32efe743 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 28 Nov 2022 18:51:04 -0500 Subject: [PATCH] Add links/mentions/hashtag to VoiceOver rotor in timelines Closes #231 --- .../TimelineStatusCollectionViewCell.swift | 21 +++++++++++++++++ .../Status/TimelineStatusTableViewCell.swift | 23 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift index 70e2f206..d9bf59da 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -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) { diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 666b8351..cdfe51f3 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -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 {