Fix links in conversation main status not being activatable with VoiceOver

Closes #272
This commit is contained in:
Shadowfacts 2022-11-28 19:13:26 -05:00
parent 7297566060
commit cf870916c9
1 changed files with 11 additions and 3 deletions

View File

@ -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
}
}
}