Improve empty state for lists (IOS-287)
This commit is contained in:
parent
50ee1c51e4
commit
07b0ddc14f
|
@ -491,6 +491,9 @@
|
|||
"offline": "Offline",
|
||||
"new_posts": "New Posts",
|
||||
"post_sent": "Post Sent"
|
||||
},
|
||||
"empty_state": {
|
||||
"list_empty_message_title": "This list is empty"
|
||||
}
|
||||
},
|
||||
"suggestion_account": {
|
||||
|
|
|
@ -29,6 +29,10 @@ final class HomeTimelineViewController: UIViewController, NeedsDependency, Media
|
|||
|
||||
let mediaPreviewTransitionController = MediaPreviewTransitionController()
|
||||
|
||||
enum EmptyViewUseCase {
|
||||
case timeline, list
|
||||
}
|
||||
|
||||
let friendsAssetImageView: UIImageView = {
|
||||
let imageView = UIImageView()
|
||||
imageView.image = Asset.Asset.friends.image
|
||||
|
@ -335,9 +339,12 @@ extension HomeTimelineViewController {
|
|||
|
||||
viewModel?.timelineIsEmpty
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] isEmpty in
|
||||
if isEmpty {
|
||||
self?.showEmptyView()
|
||||
.sink { [weak self] state in
|
||||
guard let state else {
|
||||
self?.emptyView.removeFromSuperview()
|
||||
return
|
||||
}
|
||||
self?.showEmptyView(state)
|
||||
|
||||
let userDoesntFollowPeople: Bool
|
||||
if let authContext = self?.authContext,
|
||||
|
@ -351,9 +358,6 @@ extension HomeTimelineViewController {
|
|||
self?.findPeopleButtonPressed(self)
|
||||
self?.viewModel?.presentedSuggestions = true
|
||||
}
|
||||
} else {
|
||||
self?.emptyView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
|
@ -478,7 +482,7 @@ extension HomeTimelineViewController {
|
|||
}
|
||||
|
||||
extension HomeTimelineViewController {
|
||||
func showEmptyView() {
|
||||
func showEmptyView(_ state: HomeTimelineViewModel.EmptyViewState) {
|
||||
if emptyView.superview != nil {
|
||||
return
|
||||
}
|
||||
|
@ -494,6 +498,18 @@ extension HomeTimelineViewController {
|
|||
if emptyView.arrangedSubviews.count > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
switch state {
|
||||
case .list:
|
||||
let noStatusesLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.text = L10n.Scene.HomeTimeline.EmptyState.listEmptyMessageTitle
|
||||
label.textColor = Asset.Colors.Label.secondary.color
|
||||
label.textAlignment = .center
|
||||
return label
|
||||
}()
|
||||
emptyView.addArrangedSubview(noStatusesLabel)
|
||||
case .timeline:
|
||||
let findPeopleButton: PrimaryActionButton = {
|
||||
let button = PrimaryActionButton()
|
||||
button.setTitle(L10n.Common.Controls.Actions.findPeople, for: .normal)
|
||||
|
@ -537,6 +553,7 @@ extension HomeTimelineViewController {
|
|||
buttonContainerStackView.addArrangedSubview(findPeopleButton)
|
||||
buttonContainerStackView.addArrangedSubview(manuallySearchButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Actions
|
||||
|
|
|
@ -105,6 +105,7 @@ extension HomeTimelineViewModel.LoadLatestState {
|
|||
|
||||
guard let viewModel else { return }
|
||||
|
||||
viewModel.timelineIsEmpty.send(nil)
|
||||
|
||||
Task { @MainActor in
|
||||
let latestFeedRecords = viewModel.dataController.records
|
||||
|
@ -170,7 +171,19 @@ extension HomeTimelineViewModel.LoadLatestState {
|
|||
|
||||
viewModel.dataController.records = (toAdd + latestFeedRecords).removingDuplicates()
|
||||
}
|
||||
viewModel.timelineIsEmpty.value = latestStatusIDs.isEmpty && statuses.isEmpty
|
||||
|
||||
viewModel.timelineIsEmpty.value = (latestStatusIDs.isEmpty && statuses.isEmpty) ? {
|
||||
switch viewModel.timelineContext {
|
||||
case .home:
|
||||
return .timeline
|
||||
case .public:
|
||||
return .timeline
|
||||
case .list:
|
||||
return .list
|
||||
case .hashtag:
|
||||
return .list
|
||||
}
|
||||
}() : nil
|
||||
|
||||
if !isUserInitiated {
|
||||
FeedbackGenerator.shared.generate(.impact(.light))
|
||||
|
|
|
@ -44,10 +44,14 @@ final class HomeTimelineViewModel: NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
enum EmptyViewState {
|
||||
case timeline, list
|
||||
}
|
||||
|
||||
weak var tableView: UITableView?
|
||||
weak var timelineMiddleLoaderTableViewCellDelegate: TimelineMiddleLoaderTableViewCellDelegate?
|
||||
|
||||
let timelineIsEmpty = CurrentValueSubject<Bool, Never>(false)
|
||||
let timelineIsEmpty = CurrentValueSubject<EmptyViewState?, Never>(nil)
|
||||
let homeTimelineNeedRefresh = PassthroughSubject<Void, Never>()
|
||||
|
||||
// output
|
||||
|
|
|
@ -857,6 +857,10 @@ public enum L10n {
|
|||
public enum HomeTimeline {
|
||||
/// Home
|
||||
public static let title = L10n.tr("Localizable", "Scene.HomeTimeline.Title", fallback: "Home")
|
||||
public enum EmptyState {
|
||||
/// This list is empty
|
||||
public static let listEmptyMessageTitle = L10n.tr("Localizable", "Scene.HomeTimeline.EmptyState.ListEmptyMessageTitle", fallback: "This list is empty")
|
||||
}
|
||||
public enum TimelineMenu {
|
||||
/// Following
|
||||
public static let following = L10n.tr("Localizable", "Scene.HomeTimeline.TimelineMenu.Following", fallback: "Following")
|
||||
|
|
|
@ -303,6 +303,7 @@ uploaded to Mastodon.";
|
|||
"Scene.Follower.Title" = "follower";
|
||||
"Scene.Following.Footer" = "Follows from other servers are not displayed.";
|
||||
"Scene.Following.Title" = "following";
|
||||
"Scene.HomeTimeline.EmptyState.ListEmptyMessageTitle" = "This list is empty";
|
||||
"Scene.HomeTimeline.TimelineMenu.Following" = "Following";
|
||||
"Scene.HomeTimeline.TimelineMenu.LocalCommunity" = "Local";
|
||||
"Scene.HomeTimeline.TimelineMenu.Lists.Title" = "Lists";
|
||||
|
|
Loading…
Reference in New Issue