diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index b3cd9d1..0655c10 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -27,6 +27,9 @@ public protocol RowConfigurable { public protocol RowActionable { + var editingActions: [UITableViewRowAction]? { get } + func isEditingAllowed(forIndexPath indexPath: NSIndexPath) -> Bool + func invoke(action: TableRowActionType, cell: UITableViewCell?, path: NSIndexPath) -> Any? func hasAction(action: TableRowActionType) -> Bool } @@ -49,6 +52,7 @@ public class TableRow]() + private(set) public var editingActions: [UITableViewRowAction]? public var hashValue: Int { return ObjectIdentifier(self).hashValue @@ -70,9 +74,10 @@ public class TableRow]? = nil) { + public init(item: ItemType, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { self.item = item + self.editingActions = editingActions actions?.forEach { self.actions[$0.type.key] = $0 } } @@ -92,6 +97,14 @@ public class TableRow Bool { + + if actions[TableRowActionType.canEdit.key] != nil { + return invoke(.canEdit, cell: nil, path: indexPath) as? Bool ?? false + } + return editingActions?.isEmpty == false || actions[TableRowActionType.clickDelete.key] != nil + } + // MARK: - actions - public func action(action: TableRowAction) -> Self { diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index 8407cb4..abae255 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -23,12 +23,14 @@ import UIKit public enum TableRowActionType { case click + case clickDelete case select case deselect case willSelect case willDisplay case shouldHighlight case height + case canEdit case configure case custom(String)