Browse Source

add menu-will-show observer

B. Petersen 4 years ago
parent
commit
f94c5ea332
1 changed files with 15 additions and 6 deletions
  1. 15 6
      deltachat-ios/Chat/ChatViewControllerNew.swift

+ 15 - 6
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -141,12 +141,7 @@ class ChatViewControllerNew: UITableViewController {
                                        object: nil)
         notificationCenter.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
         notificationCenter.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
-        UIMenuController.shared.menuItems = [
-            UIMenuItem(title: String.localized("info"), action: #selector(BaseMessageCell.messageInfo)),
-            UIMenuItem(title: String.localized("delete"), action: #selector(BaseMessageCell.messageDelete)),
-            UIMenuItem(title: String.localized("forward"), action: #selector(BaseMessageCell.messageForward))
-        ]
-        UIMenuController.shared.update()
+        prepareContextMenu()
     }
 
     @objc func keyboardWillShow(_ notification: Notification) {
@@ -908,10 +903,24 @@ class ChatViewControllerNew: UITableViewController {
     }
 
     // MARK: - Context menu
+    private func prepareContextMenu() {
+        UIMenuController.shared.menuItems = [
+            UIMenuItem(title: String.localized("info"), action: #selector(BaseMessageCell.messageInfo)),
+            UIMenuItem(title: String.localized("delete"), action: #selector(BaseMessageCell.messageDelete)),
+            UIMenuItem(title: String.localized("forward"), action: #selector(BaseMessageCell.messageForward))
+        ]
+        UIMenuController.shared.update()
+        NotificationCenter.default.addObserver(self, selector: #selector(ChatViewControllerNew.menuWillShow),
+                                               name: UIMenuController.willShowMenuNotification, object: nil)
+    }
+
     override func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
         return true
     }
 
+    @objc func menuWillShow(notification: NSNotification) {
+    }
+
     override func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
         return action == #selector(UIResponderStandardEditActions.copy(_:))
             || action == #selector(BaseMessageCell.messageInfo)