From 4e28dd5e88a6ac99e17176fbf967ea2a8408330e Mon Sep 17 00:00:00 2001 From: Colin Reisterer Date: Fri, 14 Dec 2018 11:42:45 -0500 Subject: [PATCH 1/2] Test to ensure duplicate calls to setRowHidden are handled Currently this test will fail, as hiding row with animation multiple times syncronously will cause unhiding to fail --- Tests/AloeStackViewTests/AloeStackViewTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tests/AloeStackViewTests/AloeStackViewTests.swift b/Tests/AloeStackViewTests/AloeStackViewTests.swift index d5a3075..21c310d 100644 --- a/Tests/AloeStackViewTests/AloeStackViewTests.swift +++ b/Tests/AloeStackViewTests/AloeStackViewTests.swift @@ -21,4 +21,16 @@ final class AloeStackViewTests: XCTestCase { func test() { } + func testSetRowHiddenDuplicateCalls() { + let stackView = AloeStackView() + let row = UIView() + stackView.addRow(row) + + stackView.setRowHidden(row, isHidden: true, animated: true) + stackView.setRowHidden(row, isHidden: true, animated: true) + stackView.setRowHidden(row, isHidden: false, animated: true) + + XCTAssertFalse(stackView.isRowHidden(row)) + } + } From 94668d6931908fb9ff538fe6dc748928cb47835f Mon Sep 17 00:00:00 2001 From: Colin Reisterer Date: Fri, 14 Dec 2018 11:52:17 -0500 Subject: [PATCH 2/2] Check that cell isHidden property has changed before setting This fixes failing test testSetRowHiddenDuplicateCalls --- Sources/AloeStackView/AloeStackView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AloeStackView/AloeStackView.swift b/Sources/AloeStackView/AloeStackView.swift index 3c17ef5..3b9fede 100644 --- a/Sources/AloeStackView/AloeStackView.swift +++ b/Sources/AloeStackView/AloeStackView.swift @@ -186,7 +186,7 @@ open class AloeStackView: UIScrollView { /// /// If `animated` is `true`, the change is animated. open func setRowHidden(_ row: UIView, isHidden: Bool, animated: Bool = false) { - guard let cell = row.superview as? StackViewCell else { return } + guard let cell = row.superview as? StackViewCell, cell.isHidden != isHidden else { return } if animated { UIView.animate(withDuration: 0.3) {