Merge pull request #83 from TouchInstinct/revert-82-fix/paginationWrapper
Revert "Fix/pagination wrapper"
This commit is contained in:
commit
557a3382f8
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<Cursor.Element>) {
|
||||
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<Cursor>.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()
|
||||
|
|
|
|||
|
|
@ -63,11 +63,7 @@ public final class PaginationViewModel<C: ResettableCursorType> {
|
|||
/// - 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<C: ResettableCursorType> {
|
|||
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<C: ResettableCursorType> {
|
|||
}
|
||||
|
||||
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<C: ResettableCursorType> {
|
|||
}
|
||||
}
|
||||
|
||||
private func reload(isRetry: Bool = false) {
|
||||
currentRequest?.dispose()
|
||||
cursor = cursor.reset()
|
||||
|
||||
if isRetry {
|
||||
internalState.value = .initial
|
||||
}
|
||||
internalState.value = .loading(after: internalState.value)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ public struct AnyLoadingIndicator: Animatable {
|
|||
/// Initializer with indicator that should be wrapped.
|
||||
///
|
||||
/// - Parameter _: indicator for wrapping.
|
||||
public init<Indicator> (_ base: Indicator, backgroundView: UIView? = nil) where Indicator: LoadingIndicator {
|
||||
self.internalView = backgroundView ?? base.view
|
||||
public init<Indicator> (_ base: Indicator) where Indicator: LoadingIndicator {
|
||||
self.internalView = base.view
|
||||
self.animatableView = base.view
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue