fix pagination wrapper
This commit is contained in:
parent
ebd8ab23a3
commit
95923bc9ca
|
|
@ -67,9 +67,7 @@ public final class PaginationDataLoadingModel<Cursor: ResettableRxDataSourceCurs
|
|||
state = .loadingMore(after: state)
|
||||
}
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in // to complete load more indicator view animation
|
||||
self?.requestData()
|
||||
}
|
||||
requestResult(from: dataSource)
|
||||
}
|
||||
|
||||
override func onGot(error: Error) {
|
||||
|
|
@ -91,8 +89,4 @@ public final class PaginationDataLoadingModel<Cursor: ResettableRxDataSourceCurs
|
|||
state = .exhausted
|
||||
}
|
||||
}
|
||||
|
||||
private func requestData() {
|
||||
requestResult(from: dataSource)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
bindViewModelStates()
|
||||
|
||||
createRefreshControl()
|
||||
|
||||
bindAppStateNotifications()
|
||||
}
|
||||
|
||||
/// Method that reload all data in internal view model.
|
||||
|
|
@ -125,7 +123,7 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
if case .initial = afterState {
|
||||
wrappedView.scrollView.isUserInteractionEnabled = false
|
||||
|
||||
removeCurrentPlaceholderView()
|
||||
removeAllPlaceholderView()
|
||||
|
||||
guard let loadingIndicator = uiDelegate?.initialLoadingIndicator() else {
|
||||
return
|
||||
|
|
@ -149,13 +147,9 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
private func onLoadingMoreState(afterState: LoadingState) {
|
||||
if case .error = afterState { // user tap retry button in table footer
|
||||
uiDelegate?.footerRetryViewWillDisappear()
|
||||
|
||||
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {
|
||||
self.wrappedView.footerView = nil // to avoid jumpy animation
|
||||
}, completion: { _ in
|
||||
self.addInfiniteScroll(withHandler: false)
|
||||
self.wrappedView.scrollView.beginInfiniteScroll(true)
|
||||
})
|
||||
wrappedView.footerView = nil
|
||||
addInfiniteScroll(withHandler: false)
|
||||
wrappedView.scrollView.beginInfiniteScroll(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -168,7 +162,7 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
if case .initialLoading = afterState {
|
||||
delegate?.paginationWrapper(didReload: newItems, using: cursor)
|
||||
|
||||
removeCurrentPlaceholderView()
|
||||
removeAllPlaceholderView()
|
||||
|
||||
wrappedView.scrollView.support.refreshControl?.endRefreshing()
|
||||
|
||||
|
|
@ -176,7 +170,8 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
} else if case .loadingMore = afterState {
|
||||
delegate?.paginationWrapper(didLoad: newItems, using: cursor)
|
||||
|
||||
readdInfiniteScrollWithHandler()
|
||||
removeAllPlaceholderView()
|
||||
readInfiniteScrollWithHandler()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +189,7 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
}
|
||||
|
||||
replacePlaceholderViewIfNeeded(with: errorView)
|
||||
} else if case .loadingMore = afterState {
|
||||
} else {
|
||||
guard let retryView = uiDelegate?.footerRetryView(),
|
||||
let retryViewHeight = uiDelegate?.footerRetryViewHeight() else {
|
||||
removeInfiniteScroll()
|
||||
|
|
@ -243,7 +238,7 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
|
||||
private func replacePlaceholderViewIfNeeded(with placeholderView: UIView) {
|
||||
wrappedView.scrollView.isUserInteractionEnabled = true
|
||||
removeCurrentPlaceholderView()
|
||||
removeAllPlaceholderView()
|
||||
|
||||
placeholderView.translatesAutoresizingMaskIntoConstraints = false
|
||||
placeholderView.isHidden = false
|
||||
|
|
@ -275,9 +270,10 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
|
||||
private func onExhaustedState() {
|
||||
removeInfiniteScroll()
|
||||
removeAllPlaceholderView()
|
||||
}
|
||||
|
||||
private func readdInfiniteScrollWithHandler() {
|
||||
private func readInfiniteScrollWithHandler() {
|
||||
removeInfiniteScroll()
|
||||
addInfiniteScroll(withHandler: true)
|
||||
}
|
||||
|
|
@ -307,9 +303,7 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
}
|
||||
|
||||
@objc private func refreshAction() {
|
||||
CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) { [weak self] in
|
||||
self?.reload()
|
||||
}
|
||||
reload()
|
||||
}
|
||||
|
||||
private func removeRefreshControl() {
|
||||
|
|
@ -318,42 +312,13 @@ final public class PaginationWrapper<Cursor: ResettableRxDataSourceCursor, Deleg
|
|||
|
||||
private func bindViewModelStates() {
|
||||
paginationViewModel.stateDriver
|
||||
.asObservable()
|
||||
.observeOn(MainScheduler.asyncInstance)
|
||||
.flatMap { [applicationCurrentlyActive] state -> Observable<LoadingState> in
|
||||
if applicationCurrentlyActive.value {
|
||||
return .just(state)
|
||||
} else {
|
||||
return applicationCurrentlyActive
|
||||
.asObservable()
|
||||
.filter { $0 }
|
||||
.delay(0.5, scheduler: MainScheduler.instance)
|
||||
.asObservable()
|
||||
.replace(with: state)
|
||||
}
|
||||
}
|
||||
.bind(to: stateChanged)
|
||||
.drive(stateChanged)
|
||||
.disposed(by: disposeBag)
|
||||
}
|
||||
|
||||
private func removeCurrentPlaceholderView() {
|
||||
private func removeAllPlaceholderView() {
|
||||
wrappedView.backgroundView = nil
|
||||
}
|
||||
|
||||
private func bindAppStateNotifications() {
|
||||
let notificationCenter = NotificationCenter.default.rx
|
||||
|
||||
notificationCenter.notification(UIApplication.willResignActiveNotification)
|
||||
.replace(with: false)
|
||||
.asDriver(onErrorJustReturn: false)
|
||||
.drive(applicationCurrentlyActive)
|
||||
.disposed(by: disposeBag)
|
||||
|
||||
notificationCenter.notification(UIApplication.didBecomeActiveNotification)
|
||||
.replace(with: true)
|
||||
.asDriver(onErrorJustReturn: true)
|
||||
.drive(applicationCurrentlyActive)
|
||||
.disposed(by: disposeBag)
|
||||
wrappedView.footerView = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue