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

@ -36,7 +36,7 @@ extension RecommendAccountSection {
viewModel: SuggestionAccountViewModel, viewModel: SuggestionAccountViewModel,
delegate: SuggestionAccountTableViewCellDelegate delegate: SuggestionAccountTableViewCellDelegate
) -> UITableViewDiffableDataSource<RecommendAccountSection, NSManagedObjectID> { ) -> UITableViewDiffableDataSource<RecommendAccountSection, NSManagedObjectID> {
UITableViewDiffableDataSource(tableView: tableView) { [weak viewModel,weak delegate] (tableView, indexPath, objectID) -> UITableViewCell? in UITableViewDiffableDataSource(tableView: tableView) { [weak viewModel, weak delegate] (tableView, indexPath, objectID) -> UITableViewCell? in
guard let viewModel = viewModel else { return nil } guard let viewModel = viewModel else { return nil }
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SuggestionAccountTableViewCell.self)) as! SuggestionAccountTableViewCell let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SuggestionAccountTableViewCell.self)) as! SuggestionAccountTableViewCell
let user = managedObjectContext.object(with: objectID) as! MastodonUser let user = managedObjectContext.object(with: objectID) as! MastodonUser

View File

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

View File

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

View File

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