Skip to content

Commit

Permalink
factor our gesture detection
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Dec 17, 2024
1 parent d061fda commit 4889e0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
9 changes: 9 additions & 0 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,15 @@ extension ChatViewController {
return nil
}

// Check if the long tap is on a link (or other message text element with custom long tap behavior)
if let msgcell = tableView.cellForRow(at: indexPath) as? BaseMessageCell {
let label = msgcell.messageLabel.label
let localTouchLocation = tableView.convert(point, to: label)
if let (detectorType, value) = label.detectGesture(localTouchLocation) {
print("url: \(detectorType) -- \(value) -- ")
}
}

return UIContextMenuConfiguration(
identifier: NSString(string: "\(messageId)"),
previewProvider: nil,
Expand Down
28 changes: 17 additions & 11 deletions deltachat-ios/Chat/Views/MessageLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,23 @@ open class MessageLabel: UILabel {

}

open func handleGesture(_ touchLocation: CGPoint) -> Bool {

guard let index = stringIndex(at: touchLocation) else { return false }

for (detectorType, ranges) in rangesForDetectors {
for (range, value) in ranges {
if range.contains(index) {
handleGesture(for: detectorType, value: value)
return true
}
}
internal func detectGesture(_ touchLocation: CGPoint) -> (DetectorType, NewMessageTextCheckingType)? {
guard let index = stringIndex(at: touchLocation) else { return nil }

for (detectorType, ranges) in rangesForDetectors {
for (range, value) in ranges {
if range.contains(index) {
return (detectorType, value)
}
}
}
return nil
}

open func handleGesture(_ touchLocation: CGPoint) -> Bool {
if let (detectorType, value) = detectGesture(touchLocation) {
handleGesture(for: detectorType, value: value)
return true
}
return false
}
Expand Down

0 comments on commit 4889e0a

Please sign in to comment.