diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 2ffc99d..568f944 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -333,13 +333,24 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { invoke(action: .didBeginMultipleSelection, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } + private var contextMenuSelectedCellIndexPath: IndexPath? @available(iOS 13.0, *) open func tableView( _ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? - { - invoke(action: .showContextMenu, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath, userInfo: [TableKitUserInfoKeys.ContextMenuInvokePoint: point]) as? UIContextMenuConfiguration + { contextMenuSelectedCellIndexPath = indexPath + return invoke(action: .showContextMenu, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath, userInfo: [TableKitUserInfoKeys.ContextMenuInvokePoint: point]) as? UIContextMenuConfiguration + } + + @available(iOS 13.0, *) + open func tableView(_ tableView: UITableView, willEndContextMenuInteraction configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) { + if tableView.hasActiveDrag || tableView.hasActiveDrop { + return + } else { + guard let indexPath = contextMenuSelectedCellIndexPath else { return } + invoke(action: .willEndContextMenuInteraction, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) + } } // MARK: - Row editing diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 526b378..5e4fd02 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -84,6 +84,7 @@ public enum TableRowActionType { case canMoveTo case move case showContextMenu + case willEndContextMenuInteraction case accessoryButtonTap case custom(String)