From a5d8f0874ae44c02e63c08e7261ebe638773268b Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Sun, 16 Oct 2016 12:45:07 +0300 Subject: [PATCH] support userInfo in custom actions --- Sources/TableDirector.swift | 6 +++--- Sources/TableKit.swift | 4 ++-- Sources/TableRow.swift | 4 ++-- Sources/TableRowAction.swift | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 63de5f7..b306b8b 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -72,8 +72,8 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { // MARK: Public @discardableResult - open func invoke(action: TableRowActionType, cell: UITableViewCell?, indexPath: IndexPath) -> Any? { - return sections[indexPath.section].rows[indexPath.row].invoke(action: action, cell: cell, path: indexPath) + open func invoke(action: TableRowActionType, cell: UITableViewCell?, indexPath: IndexPath, userInfo: [AnyHashable: Any]? = nil) -> Any? { + return sections[indexPath.section].rows[indexPath.row].invoke(action: action, cell: cell, path: indexPath, userInfo: userInfo) } open override func responds(to selector: Selector) -> Bool { @@ -93,7 +93,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { func didReceiveAction(_ notification: Notification) { guard let action = notification.object as? TableCellAction, let indexPath = tableView?.indexPath(for: action.cell) else { return } - invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath) + invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath, userInfo: notification.userInfo) } // MARK: - Height diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 656908d..7cb6d6e 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -30,7 +30,7 @@ public protocol RowActionable { var editingActions: [UITableViewRowAction]? { get } func isEditingAllowed(forIndexPath indexPath: IndexPath) -> Bool - func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath) -> Any? + func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? func has(action: TableRowActionType) -> Bool } @@ -78,7 +78,7 @@ public protocol RowAction { var id: String? { get set } var type: TableRowActionType { get } - func invokeActionOn(cell: UITableViewCell?, item: Any, path: IndexPath) -> Any? + func invokeActionOn(cell: UITableViewCell?, item: Any, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? } public protocol RowHeightCalculator { diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 3fbe569..26b7360 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -62,9 +62,9 @@ open class TableRow: Row where CellType: UITableView // MARK: - RowActionable - - open func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath) -> Any? { + open func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]? = nil) -> Any? { - return actions[action.key]?.flatMap({ $0.invokeActionOn(cell: cell, item: item, path: path) }).last + return actions[action.key]?.flatMap({ $0.invokeActionOn(cell: cell, item: item, path: path, userInfo: userInfo) }).last } open func has(action: TableRowActionType) -> Bool { diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index df415d3..9d9be52 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -71,9 +71,9 @@ open class TableRowAction: RowAction where CellType: self.handler = .action(handler) } - public func invokeActionOn(cell: UITableViewCell?, item: Any, path: IndexPath) -> Any? { + public func invokeActionOn(cell: UITableViewCell?, item: Any, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? { guard let item = item as? CellType.T else { return nil } - return handler.invoke(withOptions: TableRowActionOptions(item: item, cell: cell as? CellType, path: path, userInfo: nil)) + return handler.invoke(withOptions: TableRowActionOptions(item: item, cell: cell as? CellType, path: path, userInfo: userInfo)) } }