From eb93fe253c6862d39ba3752d9ce60c0ef35461ee Mon Sep 17 00:00:00 2001 From: mrtokii Date: Sun, 3 May 2020 16:25:30 +0300 Subject: [PATCH] Add multiple selection actions & context menu action --- Sources/TableDirector.swift | 25 +++++++++++++++++++++++++ Sources/TableKit.swift | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 4a77708..2ffc99d 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -317,6 +317,31 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return indexPath } + @available(iOS 13.0, *) + open func tableView( + _ tableView: UITableView, + shouldBeginMultipleSelectionInteractionAt indexPath: IndexPath) -> Bool + { + invoke(action: .shouldBeginMultipleSelection, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false + } + + @available(iOS 13.0, *) + open func tableView( + _ tableView: UITableView, + didBeginMultipleSelectionInteractionAt indexPath: IndexPath) + { + invoke(action: .didBeginMultipleSelection, cell: tableView.cellForRow(at: indexPath), indexPath: 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 + } + // MARK: - Row editing open func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return sections[indexPath.section].rows[indexPath.row].isEditingAllowed(forIndexPath: indexPath) diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 9202180..526b378 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -27,6 +27,7 @@ struct TableKitNotifications { public struct TableKitUserInfoKeys { public static let CellMoveDestinationIndexPath = "TableKitCellMoveDestinationIndexPath" public static let CellCanMoveProposedIndexPath = "CellCanMoveProposedIndexPath" + public static let ContextMenuInvokePoint = "ContextMenuInvokePoint" } public protocol RowConfigurable { @@ -73,6 +74,8 @@ public enum TableRowActionType { case willDisplay case didEndDisplaying case shouldHighlight + case shouldBeginMultipleSelection + case didBeginMultipleSelection case height case canEdit case configure @@ -80,6 +83,7 @@ public enum TableRowActionType { case canMove case canMoveTo case move + case showContextMenu case accessoryButtonTap case custom(String)