Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion NextcloudTalk/Chat/Chat views/MessageBodyTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct MessageBodyTextViewWrapper: UIViewRepresentable {
}
}

class MessageBodyTextView: UITextView, UITextViewDelegate {
class MessageBodyTextView: UITextView, UITextViewDelegate, UIGestureRecognizerDelegate {

private var codeBlockGestureRecognizer: UITapGestureRecognizer?

init() {
let textStorage = NSTextStorage()
Expand Down Expand Up @@ -70,9 +72,12 @@ class MessageBodyTextView: UITextView, UITextViewDelegate {
self.delegate = self

let codeBlockGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleCodeBlockTap(_:)))
self.codeBlockGestureRecognizer = codeBlockGestureRecognizer

// Don't swallow the touch, links and the message context menu need to see it as well
codeBlockGestureRecognizer.cancelsTouchesInView = false
codeBlockGestureRecognizer.delegate = self

self.addGestureRecognizer(codeBlockGestureRecognizer)
}

Expand Down Expand Up @@ -164,6 +169,13 @@ class MessageBodyTextView: UITextView, UITextViewDelegate {
NCUserInterfaceController.sharedInstance().mainViewController.present(navigationController, animated: true)
}

// MARK: - UIGestureRecognizer delegate

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// Without this our tap cancels the text view's own recognizer, which opens links
return gestureRecognizer === self.codeBlockGestureRecognizer
}

// MARK: - UITextView delegate

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
Expand Down
Loading