fix: The empty view should not display when the user just sign-in the first time

This commit is contained in:
sunxiaojian 2021-04-22 15:45:32 +08:00
parent d4f4a3e086
commit 326aea36cd
4 changed files with 15 additions and 11 deletions

View File

@ -151,16 +151,7 @@ extension HomeTimelineViewController {
UIView.animate(withDuration: 0.5) { [weak self] in
guard let self = self else { return }
self.refreshControl.endRefreshing()
} completion: { [weak self] _ in
guard let self = self else { return }
if (self.viewModel.fetchedResultsController.fetchedObjects ?? []).isEmpty {
self.showEmptyView()
} else {
self.emptyView.removeFromSuperview()
}
}
} else {
self.emptyView.removeFromSuperview()
} completion: { _ in }
}
}
.store(in: &disposeBag)
@ -191,6 +182,17 @@ extension HomeTimelineViewController {
self.publishProgressView.setProgress(progress, animated: true)
}
.store(in: &disposeBag)
viewModel.timelineIsEmpty
.receive(on: DispatchQueue.main)
.sink { [weak self] isEmpty in
if isEmpty {
self?.showEmptyView()
} else {
self?.emptyView.removeFromSuperview()
}
}
.store(in: &disposeBag)
}
override func viewWillAppear(_ animated: Bool) {

View File

@ -107,6 +107,7 @@ extension HomeTimelineViewModel.LoadLatestState {
viewModel.homeTimelineNavigationBarTitleViewModel.newPostsIncoming()
}
}
viewModel.timelineIsEmpty.value = latestStatusIDs.isEmpty && statuses.isEmpty
}
.store(in: &viewModel.disposeBag)
}

View File

@ -34,6 +34,7 @@ final class HomeTimelineViewModel: NSObject {
weak var tableView: UITableView?
weak var timelineMiddleLoaderTableViewCellDelegate: TimelineMiddleLoaderTableViewCellDelegate?
let timelineIsEmpty = CurrentValueSubject<Bool, Never>(false)
let homeTimelineNeedRefresh = PassthroughSubject<Void, Never>()
// output
// top loader