Skip to content

Commit

Permalink
#23 Added table and tableSize property also for TableCellAdapter.Event
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Sep 15, 2019
1 parent 0dcc4c3 commit 0fe87f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 0 additions & 3 deletions OwlDemo/Emoji/EmojiBrowserController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 14 additions & 13 deletions Sources/Table/Cell Adapters/TableCellAdapter+Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,32 @@ 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?

// 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
}

Expand Down

0 comments on commit 0fe87f4

Please sign in to comment.