Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Sources/Table/Cell Adapters/TableCellAdapter+Support.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public enum TableAdapterCellAction {
case deselectAnimated
}

/// Row that will be de/selected.
///
/// - none: don't de/select any row.
/// - sameRow: de/select the row where the action happened.
/// - otherRow: de/select any arbitrary row.
public enum TableAdapterCellRowSelection {
case none
case sameRow
case otherRow(at: IndexPath)
}

public extension TableCellAdapter {

// MARK: - TableAdapter.Event -
Expand Down Expand Up @@ -89,10 +100,10 @@ public extension TableCellAdapter {
public var shouldSpringLoad: ((Event) -> Bool)? = nil
public var tapOnAccessory: ((Event) -> Void)? = nil

public var willSelect: ((Event) -> IndexPath?)? = nil
public var willSelect: ((Event) -> TableAdapterCellRowSelection)? = nil
public var didSelect: ((Event) -> TableAdapterCellAction)? = nil
public var willDeselect: ((Event) -> IndexPath?)? = nil
public var didDeselect: ((Event) -> IndexPath?)? = nil
public var willDeselect: ((Event) -> TableAdapterCellRowSelection)? = nil
public var didDeselect: ((Event) -> Void)? = nil

public var willBeginEdit: ((Event) -> Void)? = nil
public var didEndEdit: ((Event) -> Void)? = nil
Expand Down
18 changes: 16 additions & 2 deletions Sources/Table/TableDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,14 @@ extension TableDirector: UITableViewDataSource, UITableViewDelegate {

public func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
let (model, adapter) = context(forItemAt: indexPath)
return (adapter.dispatchEvent(.willSelect, model: model, cell: nil, path: indexPath, params: nil) as? IndexPath) ?? indexPath
guard let rowSelection = adapter.dispatchEvent(.willSelect, model: model, cell: nil, path: indexPath, params: nil) as? TableAdapterCellRowSelection else {
return indexPath
}
switch rowSelection {
case .none: return nil
case .sameRow: return indexPath
case let .otherRow(at): return at
}
}

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand All @@ -666,7 +673,14 @@ extension TableDirector: UITableViewDataSource, UITableViewDelegate {

public func tableView(_ tableView: UITableView, willDeselectRowAt indexPath: IndexPath) -> IndexPath? {
let (model, adapter) = context(forItemAt: indexPath)
return (adapter.dispatchEvent(.willDeselect, model: model, cell: nil, path: indexPath, params: nil) as? IndexPath)
guard let rowSelection = adapter.dispatchEvent(.willDeselect, model: model, cell: nil, path: indexPath, params: nil) as? TableAdapterCellRowSelection else {
return indexPath
}
switch rowSelection {
case .none: return nil
case .sameRow: return indexPath
case let .otherRow(at): return at
}
}

public func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
Expand Down