From 492b95dfd390f1927f313556ff1356357b524da0 Mon Sep 17 00:00:00 2001 From: Eugene Lemish Date: Wed, 12 Apr 2023 16:17:35 +0300 Subject: [PATCH 1/4] add method willEndContextMenuInteraction which reload data --- Sources/TableDirector.swift | 5 +++++ Sources/TableKit.swift | 1 + 2 files changed, 6 insertions(+) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 2ffc99d..fec3345 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -341,6 +341,11 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { { 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?) { + reload() + } // MARK: - Row editing open func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 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) From 1a474fa49ee84557e953e66a6618f8354a8f3abc Mon Sep 17 00:00:00 2001 From: Eugene Lemish Date: Wed, 12 Apr 2023 16:29:59 +0300 Subject: [PATCH 2/4] remove action for row willEndDisplayContextMenuIntaraction --- Sources/TableKit.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 5e4fd02..526b378 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -84,7 +84,6 @@ public enum TableRowActionType { case canMoveTo case move case showContextMenu - case willEndContextMenuInteraction case accessoryButtonTap case custom(String) From 9a5587811acda2462ad9c8bbb21ee750f44e550d Mon Sep 17 00:00:00 2001 From: Eugene Lemish Date: Wed, 12 Apr 2023 19:14:24 +0300 Subject: [PATCH 3/4] change method willEndPerformContextMenu --- Sources/TableDirector.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index fec3345..81d62be 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -344,7 +344,12 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { @available(iOS 13.0, *) open func tableView(_ tableView: UITableView, willEndContextMenuInteraction configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) { - reload() + if tableView.hasActiveDrag || tableView.hasActiveDrop { + return + } else { + tableView.reloadData() + + } } // MARK: - Row editing From 679494bfbd88f188da38aeec3d1a696626870935 Mon Sep 17 00:00:00 2001 From: Eugene Lemish Date: Wed, 12 Apr 2023 22:55:55 +0300 Subject: [PATCH 4/4] add method willEndContextMenuInteraction to TableRowActions --- Sources/TableDirector.swift | 9 +++++---- Sources/TableKit.swift | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 81d62be..568f944 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -333,13 +333,14 @@ 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, *) @@ -347,8 +348,8 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { if tableView.hasActiveDrag || tableView.hasActiveDrop { return } else { - tableView.reloadData() - + guard let indexPath = contextMenuSelectedCellIndexPath else { return } + invoke(action: .willEndContextMenuInteraction, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } } 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)