Show "New Post 💊" if new posts (IOS-234)

This commit is contained in:
Nathan Mattes 2024-04-07 13:53:13 +02:00
parent 6f58c277c7
commit 527d250024
4 changed files with 25 additions and 5 deletions

View File

@ -318,6 +318,20 @@ extension HomeTimelineViewController {
self.timelinePillCenterXAnchor = timelinePillCenterXAnchor
self.timelinePillVisibleTopAnchor = timelinePillVisibleTopAnchor
self.timelinePillHiddenTopAnchor = timelinePillHiddenTopAnchor
viewModel?.hasNewPosts
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] hasNewPosts in
guard let self else { return }
if hasNewPosts {
self.timelinePill.update(with: .newPosts)
self.showTimelinePill()
} else {
self.hideTimelinePill()
}
})
.store(in: &disposeBag)
}
override func viewWillAppear(_ animated: Bool) {
@ -471,16 +485,18 @@ extension HomeTimelineViewController {
@objc private func timelinePillPressed(_ sender: TimelineStatusPill) {
guard let reason = sender.reason else { return }
switch reason {
case .newPosts:
print("Bring me to the new posts and disappear")
scrollToTop(animated: true)
viewModel?.hasNewPosts.value = false
case .postSent:
print("Bring me to my post and disappear")
case .offline:
print("Just disappear")
hideTimelinePill()
}
hideTimelinePill()
}
private func showTimelinePill() {

View File

@ -159,7 +159,11 @@ extension HomeTimelineViewModel.LoadLatestState {
await UIImpactFeedbackGenerator(style: .light)
.impactOccurred()
}
if newStatuses.isNotEmpty {
viewModel.hasNewPosts.value = true
}
} catch {
await enter(state: Idle.self)
viewModel.didLoadLatest.send()

View File

@ -33,6 +33,7 @@ final class HomeTimelineViewModel: NSObject {
@Published var scrollPositionRecord: ScrollPositionRecord? = nil
@Published var displaySettingBarButtonItem = true
@Published var hasPendingStatusEditReload = false
var hasNewPosts = CurrentValueSubject<Bool, Never>(false)
var timelineContext: MastodonFeed.Kind.TimelineContext = .home
weak var tableView: UITableView?

View File

@ -71,5 +71,4 @@ class TimelineStatusPill: UIButton {
}
}
}
}