mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
remove magnification and text selection on iOS, also replaced TextView URL handling
This commit is contained in:
@@ -8,14 +8,25 @@
|
|||||||
import MatrixRustSDK
|
import MatrixRustSDK
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
final class MessageTextView: UITextView, PillAttachmentViewProviderDelegate {
|
final class MessageTextView: UITextView, PillAttachmentViewProviderDelegate, UIGestureRecognizerDelegate {
|
||||||
var timelineContext: TimelineViewModel.Context?
|
var timelineContext: TimelineViewModel.Context?
|
||||||
var updateClosure: (() -> Void)?
|
var updateClosure: (() -> Void)?
|
||||||
private var pillViews = NSHashTable<UIView>.weakObjects()
|
private var pillViews = NSHashTable<UIView>.weakObjects()
|
||||||
|
|
||||||
|
override func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) {
|
||||||
|
// We don't need to change the behaviour on MacOS
|
||||||
|
if !ProcessInfo.processInfo.isiOSAppOnMac {
|
||||||
|
gestureRecognizer.delegate = self
|
||||||
|
}
|
||||||
|
super.addGestureRecognizer(gestureRecognizer)
|
||||||
|
}
|
||||||
|
|
||||||
// This prevents the magnifying glass from showing up
|
// This prevents the magnifying glass from showing up
|
||||||
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||||
gestureRecognizer as? UILongPressGestureRecognizer == nil
|
if otherGestureRecognizer is UILongPressGestureRecognizer {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func invalidateTextAttachmentsDisplay() {
|
func invalidateTextAttachmentsDisplay() {
|
||||||
@@ -72,6 +83,7 @@ struct MessageText: UIViewRepresentable {
|
|||||||
textView.adjustsFontForContentSizeCategory = true
|
textView.adjustsFontForContentSizeCategory = true
|
||||||
|
|
||||||
// Required to allow tapping links
|
// Required to allow tapping links
|
||||||
|
// We disable selection at delegate level
|
||||||
textView.isSelectable = true
|
textView.isSelectable = true
|
||||||
textView.isUserInteractionEnabled = true
|
textView.isUserInteractionEnabled = true
|
||||||
|
|
||||||
@@ -125,20 +137,22 @@ struct MessageText: UIViewRepresentable {
|
|||||||
self.openURLAction = openURLAction
|
self.openURLAction = openURLAction
|
||||||
}
|
}
|
||||||
|
|
||||||
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
|
func textViewDidChangeSelection(_ textView: UITextView) {
|
||||||
switch interaction {
|
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
|
||||||
case .invokeDefaultAction:
|
return
|
||||||
openURLAction.callAsFunction(URL)
|
|
||||||
return false
|
|
||||||
case .preview:
|
|
||||||
// We don't want to show a URL preview for permalinks
|
|
||||||
return parseMatrixEntityFrom(uri: URL.absoluteString) == nil
|
|
||||||
default:
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
textView.selectedTextRange = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 17.0, *)
|
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
|
||||||
|
if case .link(let url) = textItem.content {
|
||||||
|
return .init(title: defaultAction.title) { [weak self] _ in
|
||||||
|
self?.openURLAction.callAsFunction(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultAction
|
||||||
|
}
|
||||||
|
|
||||||
func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
|
func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
|
||||||
switch textItem.content {
|
switch textItem.content {
|
||||||
case let .link(url):
|
case let .link(url):
|
||||||
|
|||||||
Reference in New Issue
Block a user