Преглед на файлове

try-to-add-longpress-handler-and-failed

Simon Laux преди 2 години
родител
ревизия
8bfd270474

+ 15 - 1
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -257,6 +257,9 @@ public class BaseMessageCell: UITableViewCell {
         let messageLabelGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
         messageLabelGestureRecognizer.numberOfTapsRequired = 1
         messageLabel.addGestureRecognizer(messageLabelGestureRecognizer)
+        
+        let messageLabelGestureRecognizerLongTap = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(_:)))
+        messageLabel.addGestureRecognizer(messageLabelGestureRecognizer)
 
         let quoteViewGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onQuoteTapped))
         quoteViewGestureRecognizer.numberOfTapsRequired = 1
@@ -268,11 +271,22 @@ public class BaseMessageCell: UITableViewCell {
     open func handleTapGesture(_ gesture: UIGestureRecognizer) {
         guard gesture.state == .ended else { return }
         let touchLocation = gesture.location(in: messageLabel)
-        let isHandled = messageLabel.label.handleGesture(touchLocation)
+        let isHandled = messageLabel.label.handleGesture(touchLocation, isLongPress: false)
         if !isHandled, let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
             self.baseDelegate?.textTapped(indexPath: indexPath)
         }
     }
+    
+    @objc
+    open func handleLongPressGesture(_ gesture: UIGestureRecognizer) {
+        guard gesture.state == .ended else { return }
+        let touchLocation = gesture.location(in: messageLabel)
+        let isHandled = messageLabel.label.handleGesture(touchLocation, isLongPress: true)
+        if !isHandled, let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
+            self.baseDelegate?.textTapped(indexPath: indexPath)
+        }
+    }
+    
 
     @objc func onAvatarTapped() {
         if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {

+ 17 - 3
deltachat-ios/Chat/Views/MessageLabel.swift

@@ -452,21 +452,25 @@ open class MessageLabel: UILabel {
 
     }
 
-  open func handleGesture(_ touchLocation: CGPoint) -> Bool {
+    open func handleGesture(_ touchLocation: CGPoint, isLongPress: Bool) -> 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)
+                    if isLongPress {
+                        handleLongPressGesture(for: detectorType, value: value)
+                    } else {
+                        handleGesture(for: detectorType, value: value)
+                    }
                     return true
                 }
             }
         }
         return false
     }
-
+    
     /// swiftlint:disable cyclomatic_complexity
     private func handleGesture(for detectorType: DetectorType, value: NewMessageTextCheckingType) {
         switch value {
@@ -507,6 +511,16 @@ open class MessageLabel: UILabel {
             }
         }
     }
+    private func handleLongPressGesture(for detectorType: DetectorType, value: NewMessageTextCheckingType) {
+        switch value {
+        case let .link(url):
+            guard let url = url else { return }
+            // handleURL(url)
+            print("long press url", url)
+        default:
+            return
+        }
+    }
     // swiftlint:enable cyclomatic_complexity
 
     private func handleAddress(_ addressComponents: [String: String]) {

+ 1 - 1
deltachat-ios/View/MultilineLabelCell.swift

@@ -55,7 +55,7 @@ class MultilineLabelCell: UITableViewCell {
     open func handleTapGesture(_ gesture: UIGestureRecognizer) {
         guard gesture.state == .ended else { return }
         let touchLocation = gesture.location(in: label)
-        let isHandled = label.handleGesture(touchLocation)
+        let isHandled = label.handleGesture(touchLocation, isLongPress: false)
         if !isHandled {
             logger.info("status: tapped outside urls or phone numbers")
         }