mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Restored Link long pressing (#2449)
This commit is contained in:
@@ -128,6 +128,7 @@ struct MessageText: UIViewRepresentable {
|
|||||||
|
|
||||||
final class Coordinator: NSObject, UITextViewDelegate {
|
final class Coordinator: NSObject, UITextViewDelegate {
|
||||||
var openURLAction: OpenURLAction
|
var openURLAction: OpenURLAction
|
||||||
|
let permalinkBaseURL = ServiceLocator.shared.settings.permalinkBaseURL
|
||||||
|
|
||||||
init(openURLAction: OpenURLAction) {
|
init(openURLAction: OpenURLAction) {
|
||||||
self.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 {
|
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
|
||||||
if interaction == .invokeDefaultAction {
|
switch interaction {
|
||||||
|
case .invokeDefaultAction:
|
||||||
openURLAction.callAsFunction(URL)
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
.shadow(color: .black.opacity(isLongPressing ? 0.1 : 0.0), radius: isLongPressing ? 3 : 0)
|
.shadow(color: .black.opacity(isLongPressing ? 0.1 : 0.0), radius: isLongPressing ? 3 : 0)
|
||||||
.scaleEffect(x: isLongPressing ? 1.05 : 1,
|
.scaleEffect(x: isLongPressing ? 1.05 : 1,
|
||||||
y: isLongPressing ? 1.05 : 1)
|
y: isLongPressing ? 1.05 : 1)
|
||||||
.animation(.spring(response: 0.5).delay(isLongPressing ? 0.1 : 0).disabledDuringTests(),
|
.animation(.spring(response: 0.7).delay(isLongPressing ? 0.1 : 0).disabledDuringTests(),
|
||||||
value: isLongPressing)
|
value: isLongPressing)
|
||||||
// The minimum duration here doesn't actually invoke the perform block when elapsed (thus
|
// The minimum duration here doesn't actually invoke the perform block when elapsed (thus
|
||||||
// the implementation below) but it does cancel other system gestures e.g. swipe to reply
|
// the implementation below) but it does cancel other system gestures e.g. swipe to reply
|
||||||
@@ -45,7 +45,8 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
feedbackGenerator.prepare()
|
feedbackGenerator.prepare()
|
||||||
|
|
||||||
triggerTask = Task {
|
triggerTask = Task {
|
||||||
try? await Task.sleep(for: .seconds(0.35))
|
// The wait time needs to be at least 0.5 seconds or the long press gesture will take precedence over long pressing links.
|
||||||
|
try? await Task.sleep(for: .seconds(0.5))
|
||||||
|
|
||||||
if Task.isCancelled { return }
|
if Task.isCancelled { return }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Long pressing a link will give the preview and the context menu to copy it (or open it in Safari).
|
||||||
Reference in New Issue
Block a user