Adjust loading footer display interval behavior

This commit is contained in:
Justin Mazzocchi 2021-02-01 15:10:37 -08:00
parent 699fff540e
commit c6d644feaf
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -251,7 +251,7 @@ extension TableViewController: ZoomAnimatorDelegate {
private extension TableViewController { private extension TableViewController {
static let bottomInset: CGFloat = .newStatusButtonDimension + .defaultSpacing * 4 static let bottomInset: CGFloat = .newStatusButtonDimension + .defaultSpacing * 4
static let loadingFooterDebounceInterval: TimeInterval = 0.5 static let loadingFooterDebounceInterval: TimeInterval = 0.75
var bottomInset: CGFloat { insetBottom ? Self.bottomInset : 0 } var bottomInset: CGFloat { insetBottom ? Self.bottomInset : 0 }
@ -279,19 +279,21 @@ private extension TableViewController {
viewModel.loading.receive(on: DispatchQueue.main).assign(to: &$loading) viewModel.loading.receive(on: DispatchQueue.main).assign(to: &$loading)
$loading.combineLatest(
$loading.debounce( $loading.debounce(
for: .seconds(Self.loadingFooterDebounceInterval), for: .seconds(Self.loadingFooterDebounceInterval),
scheduler: DispatchQueue.main) scheduler: DispatchQueue.main))
.sink { [weak self] in .sink { [weak self] loading, debouncedLoading in
guard let self = self else { return } guard let self = self else { return }
let refreshControlVisibile = self.refreshControl?.isRefreshing ?? false let refreshControlVisibile = self.refreshControl?.isRefreshing ?? false
if !$0, refreshControlVisibile { if !loading, refreshControlVisibile {
self.refreshControl?.endRefreshing() self.refreshControl?.endRefreshing()
} }
self.tableView.tableFooterView = $0 && !refreshControlVisibile ? self.loadingTableFooterView : UIView() self.tableView.tableFooterView =
loading && debouncedLoading && !refreshControlVisibile ? self.loadingTableFooterView : UIView()
self.sizeTableHeaderFooterViews() self.sizeTableHeaderFooterViews()
} }
.store(in: &cancellables) .store(in: &cancellables)