From 9ae69b71cad00c1bd2e7ee706dfee778be90ab00 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Fri, 14 Oct 2016 20:56:52 +0300 Subject: [PATCH] add RowAction protocol --- Sources/TableRow.swift | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index b05cada..a86b500 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -48,6 +48,36 @@ public protocol Row: RowConfigurable, RowActionable, RowHashable { var defaultHeight: CGFloat? { get } } + + + + + +public protocol RowAction { + + func invokeActionOn(cell: CellType, item: CellType.T, path: IndexPath) -> Any? where CellType: UITableViewCell +} + + + + +open class TableRowActionX: RowAction where ActionCellType: UITableViewCell { + + var handler: ((TableRowActionData) -> Void)? + + public func invokeActionOn(cell: CellType, item: CellType.T, path: IndexPath) -> Any? where CellType: UITableViewCell { + + guard let item = item as? ActionCellType.T else { return nil } + + let x = TableRowActionData(item: item, cell: cell as? ActionCellType, path: path, userInfo: nil) + + handler?(x) + + return nil + } +} + + open class TableRow: Row where CellType: UITableViewCell { open let item: CellType.T