Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ‘Row’ model to selection handler #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ extension DataSource: UITableViewDelegate {
}

if let row = row(at: indexPath) {
row.selection?()
row.selection?(row)
}

tableViewDelegate?.tableView?(tableView, didSelectRowAt: indexPath)
}

public func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
if let row = row(at: indexPath) {
row.accessory.selection?()
row.accessory.selection?(row)
}

tableViewDelegate?.tableView?(tableView, accessoryButtonTappedForRowWith: indexPath)
Expand Down
2 changes: 1 addition & 1 deletion Static/Row.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

/// Row or Accessory selection callback.
public typealias Selection = () -> Void
public typealias Selection = (Row) -> Void
public typealias ValueChange = (Bool) -> ()
public typealias SegmentedControlValueChange = (Int, Any?) -> ()

Expand Down
6 changes: 3 additions & 3 deletions Static/Tests/DataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ class DataSourceTests: XCTestCase {
XCTAssertFalse(dataSource.tableView(tableView, shouldHighlightRowAt: IndexPath(row: 0, section: 0)))

dataSource.sections = [
Section(rows: [Row(text: "Cupcakes", selection: {})])
Section(rows: [Row(text: "Cupcakes", selection: { (row) in })])
]
XCTAssertTrue(dataSource.tableView(tableView, shouldHighlightRowAt: IndexPath(row: 0, section: 0)))
}

func testSelection() {
let expectation = self.expectation(description: "Selected")
let selection = {
let selection: Selection = { (row) in
expectation.fulfill()
}

Expand All @@ -112,7 +112,7 @@ class DataSourceTests: XCTestCase {

func testAccessorySelection() {
let expectation = self.expectation(description: "Accessory Selected")
let selection = {
let selection: Selection = { (row) in
expectation.fulfill()
}

Expand Down
4 changes: 2 additions & 2 deletions Static/Tests/RowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Static
class RowTests: XCTestCase {

func testInit() {
let selection: Selection = {}
let selection: Selection = { (row) in }
let context: Row.Context = [
"Hello": "world"
]
Expand Down Expand Up @@ -36,7 +36,7 @@ class RowTests: XCTestCase {
}

func testInitWithSelectableAccessoryType() {
let selection: Selection = {}
let selection: Selection = { (row) in }
let accessory: Row.Accessory = .detailButton(selection)

let row = Row(accessory: accessory)
Expand Down