From bd4d423aec5510292d69b1bb6100b704cb6311c4 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 11 May 2017 13:15:12 +0300 Subject: [PATCH 1/2] add test for StaticCursor --- LeadKit/Tests/CursorTests.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/LeadKit/Tests/CursorTests.swift b/LeadKit/Tests/CursorTests.swift index 9e425804..fdb6e08c 100644 --- a/LeadKit/Tests/CursorTests.swift +++ b/LeadKit/Tests/CursorTests.swift @@ -85,4 +85,21 @@ class CursorTests: XCTestCase { waitForExpectations(timeout: 10, handler: nil) } + func testStaticCursor() { + let cursor = StaticCursor(content: Array(1...40).map(String.init)) + + let cursorExpectation = expectation(description: "Static cursor expectation") + + cursor.loadNextBatch().subscribe(onSuccess: { loadedItems in + XCTAssertEqual(loadedItems.count, 40) + + cursorExpectation.fulfill() + }) { error in + XCTFail(error.localizedDescription) + } + .addDisposableTo(disposeBag) + + waitForExpectations(timeout: 10, handler: nil) + } + } From e53241696b77c4a4c1b6c32d28c932f69ec94598 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 11 May 2017 14:04:47 +0300 Subject: [PATCH 2/2] fix pagination bugs --- .../Pagination/PaginationTableViewWrapper.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/LeadKit/Sources/Classes/Pagination/PaginationTableViewWrapper.swift b/LeadKit/Sources/Classes/Pagination/PaginationTableViewWrapper.swift index 6c6b8d72..393fdfe9 100644 --- a/LeadKit/Sources/Classes/Pagination/PaginationTableViewWrapper.swift +++ b/LeadKit/Sources/Classes/Pagination/PaginationTableViewWrapper.swift @@ -178,7 +178,7 @@ where Delegate.Cursor == Cursor { currentPlaceholderView = loadingIndicatorView } else { - tableView.finishInfiniteScroll() + removeInfiniteScroll() tableView.tableFooterView = nil } } @@ -224,9 +224,7 @@ where Delegate.Cursor == Cursor { currentPlaceholderView = errorView } else if case .loadingMore = afterState { - tableView.finishInfiniteScroll() - - tableView.removeInfiniteScroll() + removeInfiniteScroll() guard let retryButton = delegate?.retryLoadMoreButton(forPaginationWrapper: self), let retryButtonHeigth = delegate?.retryLoadMoreButtonHeight(forPaginationWrapper: self) else { @@ -260,7 +258,7 @@ where Delegate.Cursor == Cursor { // MARK: private stuff private func onExhaustedState() { - tableView.removeInfiniteScroll() + removeInfiniteScroll() } private func addInfiniteScroll() { @@ -271,6 +269,11 @@ where Delegate.Cursor == Cursor { tableView.infiniteScrollIndicatorView = delegate?.loadingMoreIndicator(forPaginationWrapper: self).view } + private func removeInfiniteScroll() { + tableView.finishInfiniteScroll() + tableView.removeInfiniteScroll() + } + private func createRefreshControl() { let refreshControl = UIRefreshControl() refreshControl.rx.controlEvent(.valueChanged) @@ -285,7 +288,7 @@ where Delegate.Cursor == Cursor { private func bindViewModelStates() { typealias State = PaginationViewModel.State - paginationViewModel.state.flatMapLatest { [applicationCurrentyActive] state -> Driver in + paginationViewModel.state.flatMap { [applicationCurrentyActive] state -> Driver in if applicationCurrentyActive.value { return .just(state) } else {