Browse Source

handle iOS 12 context menu

nayooti 4 years ago
parent
commit
9a86eb29d4

+ 6 - 1
deltachat-ios/Controller/GalleryViewController.swift

@@ -100,6 +100,7 @@ class GalleryViewController: UIViewController {
 
     private func setupContextMenuIfNeeded() {
         UIMenuController.shared.menuItems = [
+            UIMenuItem(title: String.localized("show_in_chat"), action: #selector(GalleryCell.showInChat(_:))),
             UIMenuItem(title: String.localized("delete"), action: #selector(GalleryCell.itemDelete(_:))),
         ]
         UIMenuController.shared.update()
@@ -201,7 +202,9 @@ extension GalleryViewController: UICollectionViewDataSource, UICollectionViewDel
     // MARK: - context menu
     // context menu for iOS 11, 12
     func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
-        return action ==  #selector(GalleryCell.itemDelete(_:))
+        return
+            action ==  #selector(GalleryCell.itemDelete(_:)) ||
+            action == #selector(GalleryCell.showInChat(_:))
     }
 
     func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) {
@@ -209,6 +212,8 @@ extension GalleryViewController: UICollectionViewDataSource, UICollectionViewDel
         switch action {
         case #selector(GalleryCell.itemDelete(_:)):
             self.askToDeleteItem(at: indexPath)
+        case #selector(GalleryCell.showInChat(_:)):
+            self.redirectToMessage(of: indexPath)
         default:
             break
         }

+ 4 - 0
deltachat-ios/View/Cell/GalleryCell.swift

@@ -71,6 +71,10 @@ class GalleryCell: UICollectionViewCell {
         self.performAction(#selector(GalleryCell.itemDelete(_:)), with: sender)
     }
 
+    @objc func showInChat(_ sender: Any) {
+        self.performAction(#selector(GalleryCell.showInChat(_:)), with: sender)
+    }
+
     func performAction(_ action: Selector, with sender: Any?) {
         if let collectionView = self.superview as? UICollectionView, let indexPath = collectionView.indexPath(for: self) {
             collectionView.delegate?.collectionView?(