Merge pull request #69 from TouchInstinct/bugfix

fix pagination bugs
This commit is contained in:
Nikolai Ashanin 2017-05-15 18:41:51 +03:00 committed by GitHub
commit 680e588e4d
2 changed files with 26 additions and 6 deletions

View File

@ -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<Cursor>.State
paginationViewModel.state.flatMapLatest { [applicationCurrentyActive] state -> Driver<State> in
paginationViewModel.state.flatMap { [applicationCurrentyActive] state -> Driver<State> in
if applicationCurrentyActive.value {
return .just(state)
} else {

View File

@ -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)
}
}