Skip to content

Commit 90ed1f7

Browse files
author
Erik Strottmann
authored
Merge pull request #14 from clutter/single-selection-preselection
Fix bugs in SingleSelection preselection
2 parents 788b487 + 2d6b1d3 commit 90ed1f7

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

Example/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PODS:
22
- SwiftLint (0.34.0)
3-
- TiltUp (0.4.3)
4-
- TiltUpTest (0.4.3)
3+
- TiltUp (0.5.0)
4+
- TiltUpTest (0.5.0)
55

66
DEPENDENCIES:
77
- SwiftLint
@@ -20,8 +20,8 @@ EXTERNAL SOURCES:
2020

2121
SPEC CHECKSUMS:
2222
SwiftLint: 79d48a17c6565dc286c37efb8322c7b450f95c67
23-
TiltUp: 2b6d8db8ee1152dd4a95b38fc6b391cd791dc936
24-
TiltUpTest: 7cbd1a189fa2055d561105a92c23af6867b2a1ed
23+
TiltUp: 3d2960016f9e2ff4cee3201b9418d1a76470a5cd
24+
TiltUpTest: 151fd6ff45b85f41ba5d3b5845c29464422e8914
2525

2626
PODFILE CHECKSUM: c3ad4c36e5d17d3b4a90d5cf5f5b66d3221db5dd
2727

Example/Tests/Screens/SingleSelection/SingleSelectionViewModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class SingleSelectionViewModelTests: XCTestCase {
2424

2525
func testCheckmarks() {
2626
let viewModel = SingleSelectionViewModel<TestRow>(rows: [.row1, .row2], navTitle: "Test")
27-
viewModel.selectedRow(at: IndexPath(row: 0, section: 0))
27+
viewModel.preselectRow(at: IndexPath(row: 0, section: 0))
2828
}
2929

3030
func testCancel() {
@@ -43,7 +43,7 @@ final class SingleSelectionViewModelTests: XCTestCase {
4343
var confirmedRow: TestRow?
4444
viewModel.coordinatorObservers.tappedConfirm = { confirmedRow = $0 }
4545

46-
viewModel.selectedRow(at: IndexPath(row: 0, section: 0))
46+
viewModel.preselectRow(at: IndexPath(row: 0, section: 0))
4747
viewModel.tappedConfirmButton()
4848
XCTAssertEqual(confirmedRow, .row1)
4949
}

TiltUp.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'TiltUp'
11-
s.version = '0.4.3'
11+
s.version = '0.5.0'
1212
s.summary = 'Official Clutter SDK in Swift to access core iOS features.'
1313

1414
# This description is used to generate tags and improve search results.

TiltUp/Classes/Screens/SingleSelection/SingleSelectionController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public final class SingleSelectionController<Value: SingleSelectionableRow>: UIT
2626
public override func viewDidLoad() {
2727
super.viewDidLoad()
2828

29+
clearsSelectionOnViewWillAppear = false
30+
2931
if navigationController?.viewControllers.first == self {
3032
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(tappedCancelButton))
3133
}

TiltUp/Classes/Screens/SingleSelection/SingleSelectionViewModel.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public final class SingleSelectionViewModel<Value: SingleSelectionableRow> {
143143

144144
// MARK: - Actions
145145

146-
public func selectedRow(at indexPath: IndexPath) {
146+
private func updateSelection(to indexPath: IndexPath) {
147147
for (sectionIndex, section) in sections.enumerated() {
148148
for (rowIndex, row) in section.rows.enumerated() where row.isSelected {
149149
sections[sectionIndex].rows[rowIndex].isSelected = false
@@ -155,6 +155,14 @@ public final class SingleSelectionViewModel<Value: SingleSelectionableRow> {
155155

156156
viewObservers.confirmButtonEnabled?(selectedIndexPath != nil)
157157
viewObservers.confirmButtonTitle?(confirmButtonTitle)
158+
}
159+
160+
public func preselectRow(at indexPath: IndexPath) {
161+
updateSelection(to: indexPath)
162+
}
163+
164+
func selectedRow(at indexPath: IndexPath) {
165+
updateSelection(to: indexPath)
158166

159167
let value = sections[indexPath.section].rows[indexPath.row].value
160168
if value.singleSelectionableRow.hasNextStep {

TiltUpTest.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'TiltUpTest'
11-
s.version = '0.4.3'
11+
s.version = '0.5.0'
1212
s.summary = 'Official Clutter SDK in Swift to access core iOS test helpers.'
1313

1414
# This description is used to generate tags and improve search results.

0 commit comments

Comments
 (0)