From 3421553e6c4216544d216173dd1095053446f6a3 Mon Sep 17 00:00:00 2001 From: Daniele Margutti Date: Sun, 15 Sep 2019 10:22:31 +0200 Subject: [PATCH] Added table and tableSize property also for TableCellAdapter.Event --- OwlDemo/Emoji/EmojiBrowserController.swift | 3 --- .../TableCellAdapter+Events.swift | 27 ++++++++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/OwlDemo/Emoji/EmojiBrowserController.swift b/OwlDemo/Emoji/EmojiBrowserController.swift index 37f19ca..0a9ad45 100644 --- a/OwlDemo/Emoji/EmojiBrowserController.swift +++ b/OwlDemo/Emoji/EmojiBrowserController.swift @@ -36,9 +36,6 @@ public class EmojiBrowserController: UIViewController { adapter.events.itemSize = { ctx in return CGSize(width: 50, height: 50) } - adapter.events.endDisplay = { ctx in - debugPrint("end!") - } } director?.registerAdapter(emojiAdapter) diff --git a/Sources/Table/Cell Adapters/TableCellAdapter+Events.swift b/Sources/Table/Cell Adapters/TableCellAdapter+Events.swift index fa1f869..a23d466 100644 --- a/Sources/Table/Cell Adapters/TableCellAdapter+Events.swift +++ b/Sources/Table/Cell Adapters/TableCellAdapter+Events.swift @@ -34,7 +34,18 @@ public extension TableCellAdapter { class Event { // Related table. - public private(set) weak var table: UITableView? + public var table: UITableView? { + guard let cell = (cell as? UITableViewCell), + let table = cell.superview as? UITableView else { + return nil + } + return table + } + + /// Managed source table's bounds size + public var tableSize: CGSize? { + return table?.bounds.size + } // Source index path, if available. public let indexPath: IndexPath? @@ -42,23 +53,13 @@ public extension TableCellAdapter { // Target element of the event. public let element: Model? - private let _cell: Cell? - // Target static typed cell if available. // This value maybe `nil` if, at the time of the request, no cell is contextually associable with the event. - public var cell: Cell? { - guard let indexPath = indexPath else { - return nil - } - guard let cell = _cell else { - return table?.cellForRow(at: indexPath) as? Cell - } - return cell - } + public var cell: Cell? internal init(item: Any? = nil, cell: Any? = nil, indexPath: IndexPath? = nil) { self.element = item as? Model - self._cell = cell as? Cell + self.cell = cell as? Cell self.indexPath = indexPath }