From cf870916c9b477726c2a4516828c6dc1cbad550f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 28 Nov 2022 19:13:26 -0500 Subject: [PATCH] Fix links in conversation main status not being activatable with VoiceOver Closes #272 --- Tusker/Views/ContentTextView.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index e3c47c40..23c2b204 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -14,6 +14,7 @@ import WebURL import WebURLFoundationExtras private let emojiRegex = try! NSRegularExpression(pattern: ":(\\w+):", options: []) +private let dataDetectorsScheme = "x-apple-data-detectors" class ContentTextView: LinkTextView, BaseEmojiLabel { @@ -198,7 +199,8 @@ class ContentTextView: LinkTextView, BaseEmojiLabel { } let location = recognizer.location(in: self) - if let (link, range) = getLinkAtPoint(location) { + if let (link, range) = getLinkAtPoint(location), + link.scheme != dataDetectorsScheme { let text = (self.text as NSString).substring(with: range) handleLinkTapped(url: link, text: text) } @@ -287,9 +289,15 @@ class ContentTextView: LinkTextView, BaseEmojiLabel { extension ContentTextView: UITextViewDelegate { func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { - // generally disable the text view's link interactions, we handle tapping links ourself with a gesture recognizer // the builtin data detectors use the x-apple-data-detectors scheme, and we allow the text view to handle those itself - return URL.scheme == "x-apple-data-detectors" + if URL.scheme == dataDetectorsScheme { + return true + } else { + // otherwise, regular taps are handled by the gesture recognizer, but the accessibility interaction to select links with the rotor goes through here + // and this seems to be the only way of overriding what it does + handleLinkTapped(url: URL, text: (text as NSString).substring(with: characterRange)) + return false + } } }