Skip to content

add new action #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Sources/TableDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TableKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public enum TableRowActionType {
case canMoveTo
case move
case showContextMenu
case willEndContextMenuInteraction
case accessoryButtonTap
case custom(String)

Expand Down