diff --git a/LeadKit.podspec b/LeadKit.podspec index 389b855d..63b59d06 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.5.5" + s.version = "0.5.4" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/Sources/Classes/Pagination/PaginationTableViewWrapper.swift b/Sources/Classes/Pagination/PaginationTableViewWrapper.swift index e0b2e591..a879914a 100644 --- a/Sources/Classes/Pagination/PaginationTableViewWrapper.swift +++ b/Sources/Classes/Pagination/PaginationTableViewWrapper.swift @@ -142,11 +142,6 @@ where Delegate.Cursor == Cursor { paginationViewModel.load(.reload) } - /// Method acts like reload, but shows initial loading view after being invoked. - public func retry() { - paginationViewModel.load(.retry) - } - /// Method that enables placeholders animation due pull-to-refresh interaction. /// /// - Parameter scrollObservable: Observable that emits content offset as CGPoint. @@ -209,9 +204,7 @@ where Delegate.Cursor == Cursor { tableView.support.refreshControl?.endRefreshing() - if !(cursor is SingleLoadCursor) { - addInfiniteScroll() - } + addInfiniteScroll() } else if case .loadingMore = afterState { delegate?.paginationWrapper(wrapper: self, didLoad: newItems, usingCursor: cursor) @@ -221,15 +214,15 @@ where Delegate.Cursor == Cursor { private func onErrorState(error: Error, afterState: PaginationViewModel.State) { if case .loading = afterState { - defer { - tableView.support.refreshControl?.endRefreshing() - } + enterPlaceholderState() guard let errorView = delegate?.errorPlaceholder(forPaginationWrapper: self, forError: error) else { return } - replacePlaceholderViewIfNeeded(with: errorView) + preparePlaceholderView(errorView) + + currentPlaceholderView = errorView } else if case .loadingMore = afterState { removeInfiniteScroll() @@ -251,23 +244,15 @@ where Delegate.Cursor == Cursor { } private func onEmptyState() { - defer { - tableView.support.refreshControl?.endRefreshing() - } + enterPlaceholderState() + guard let emptyView = delegate?.emptyPlaceholder(forPaginationWrapper: self) else { return } - replacePlaceholderViewIfNeeded(with: emptyView) - } - private func replacePlaceholderViewIfNeeded(with view: UIView) { - // don't update placeholder view if previous placeholder is the same one - if currentPlaceholderView === view { - return - } - enterPlaceholderState() - preparePlaceholderView(view) - currentPlaceholderView = view + preparePlaceholderView(emptyView) + + currentPlaceholderView = emptyView } // MARK: - private stuff @@ -337,6 +322,7 @@ where Delegate.Cursor == Cursor { } private func enterPlaceholderState() { + tableView.support.refreshControl?.endRefreshing() tableView.isUserInteractionEnabled = true removeCurrentPlaceholderView() diff --git a/Sources/Classes/Pagination/PaginationViewModel.swift b/Sources/Classes/Pagination/PaginationViewModel.swift index d5de6da9..59d3fa03 100644 --- a/Sources/Classes/Pagination/PaginationViewModel.swift +++ b/Sources/Classes/Pagination/PaginationViewModel.swift @@ -63,11 +63,7 @@ public final class PaginationViewModel { /// - next: load next batch of items. public enum LoadType { - /// pull-to-refresh case reload - /// retry button inside placeholder - case retry - case next } @@ -98,9 +94,10 @@ public final class PaginationViewModel { public func load(_ loadType: LoadType) { switch loadType { case .reload: - reload() - case .retry: - reload(isRetry: true) + currentRequest?.dispose() + cursor = cursor.reset() + + internalState.value = .loading(after: internalState.value) case .next: if case .exhausted(_) = internalState.value { fatalError("You shouldn't call load(.next) after got .exhausted state!") @@ -121,11 +118,6 @@ public final class PaginationViewModel { } private func onGot(newItems: [C.Element], using cursor: C) { - if newItems.isEmpty { - internalState.value = .empty - return - } - internalState.value = .results(newItems: newItems, inCursor: cursor, after: internalState.value) if cursor.exhausted { @@ -146,14 +138,4 @@ public final class PaginationViewModel { } } - private func reload(isRetry: Bool = false) { - currentRequest?.dispose() - cursor = cursor.reset() - - if isRetry { - internalState.value = .initial - } - internalState.value = .loading(after: internalState.value) - } - } diff --git a/Sources/Structures/Views/AnyLoadingIndicator.swift b/Sources/Structures/Views/AnyLoadingIndicator.swift index ebdf7422..3e5fbbcb 100644 --- a/Sources/Structures/Views/AnyLoadingIndicator.swift +++ b/Sources/Structures/Views/AnyLoadingIndicator.swift @@ -31,8 +31,8 @@ public struct AnyLoadingIndicator: Animatable { /// Initializer with indicator that should be wrapped. /// /// - Parameter _: indicator for wrapping. - public init (_ base: Indicator, backgroundView: UIView? = nil) where Indicator: LoadingIndicator { - self.internalView = backgroundView ?? base.view + public init (_ base: Indicator) where Indicator: LoadingIndicator { + self.internalView = base.view self.animatableView = base.view } diff --git a/Tests/CursorTests.swift b/Tests/CursorTests.swift index cba3e0bd..fdb6e08c 100644 --- a/Tests/CursorTests.swift +++ b/Tests/CursorTests.swift @@ -94,9 +94,9 @@ class CursorTests: XCTestCase { XCTAssertEqual(loadedItems.count, 40) cursorExpectation.fulfill() - }, onError: { error in + }) { error in XCTFail(error.localizedDescription) - }) + } .addDisposableTo(disposeBag) waitForExpectations(timeout: 10, handler: nil)