visionOS: Don't use deprecated UITextViewDelegate method

This commit is contained in:
Shadowfacts 2024-02-03 12:24:05 -05:00
parent f122383d0b
commit dc654812b1
1 changed files with 15 additions and 0 deletions

View File

@ -236,6 +236,20 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
}
extension ContentTextView: UITextViewDelegate {
#if os(visionOS)
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
guard case .link(let url) = textItem.content else {
return defaultAction
}
if url.scheme == dataDetectorsScheme {
return defaultAction
} else {
return UIAction { _ in
self.handleLinkTapped(url: url, text: (self.text as NSString).substring(with: textItem.range))
}
}
}
#else
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
// the builtin data detectors use the x-apple-data-detectors scheme, and we allow the text view to handle those itself
if URL.scheme == dataDetectorsScheme {
@ -249,6 +263,7 @@ extension ContentTextView: UITextViewDelegate {
return false
}
}
#endif
}
extension ContentTextView: MenuActionProvider {