mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Restored Link long pressing (#2449)
This commit is contained in:
@@ -128,6 +128,7 @@ struct MessageText: UIViewRepresentable {
|
||||
|
||||
final class Coordinator: NSObject, UITextViewDelegate {
|
||||
var openURLAction: OpenURLAction
|
||||
let permalinkBaseURL = ServiceLocator.shared.settings.permalinkBaseURL
|
||||
|
||||
init(openURLAction: OpenURLAction) {
|
||||
self.openURLAction = openURLAction
|
||||
@@ -138,10 +139,28 @@ struct MessageText: UIViewRepresentable {
|
||||
}
|
||||
|
||||
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
|
||||
if interaction == .invokeDefaultAction {
|
||||
switch interaction {
|
||||
case .invokeDefaultAction:
|
||||
openURLAction.callAsFunction(URL)
|
||||
return false
|
||||
case .preview:
|
||||
// We don't want to show a URL preview for permalinks
|
||||
return PermalinkBuilder.detectPermalink(in: URL, baseURL: permalinkBaseURL) == nil
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17.0, *)
|
||||
func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
|
||||
switch textItem.content {
|
||||
case let .link(url):
|
||||
// We don't want to show a URL preview for permalinks
|
||||
let isPermalink = PermalinkBuilder.detectPermalink(in: url, baseURL: permalinkBaseURL) != nil
|
||||
return .init(preview: isPermalink ? nil : .default, menu: defaultMenu)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user