Restore tap on status counter

This commit is contained in:
Thomas Ricouard 2024-09-19 10:10:25 +02:00
parent db7155423a
commit 12b6c1af36
2 changed files with 28 additions and 5 deletions

View file

@ -32,13 +32,17 @@ import SwiftUI
} }
struct TimelineUnreadStatusesView: View { struct TimelineUnreadStatusesView: View {
@State var observer: TimelineUnreadStatusesObserver
@Environment(UserPreferences.self) private var preferences @Environment(UserPreferences.self) private var preferences
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@State var observer: TimelineUnreadStatusesObserver
let onButtonTap: (String?) -> Void
var body: some View { var body: some View {
if observer.pendingStatusesCount > 0 || observer.isLoadingNewStatuses { if observer.pendingStatusesCount > 0 || observer.isLoadingNewStatuses {
Button { } label: { Button {
onButtonTap(observer.pendingStatuses.last)
} label: {
HStack(spacing: 8) { HStack(spacing: 8) {
if observer.isLoadingNewStatuses { if observer.isLoadingNewStatuses {
ProgressView() ProgressView()

View file

@ -21,6 +21,8 @@ public struct TimelineView: View {
@State private var viewModel = TimelineViewModel() @State private var viewModel = TimelineViewModel()
@State private var contentFilter = TimelineContentFilter.shared @State private var contentFilter = TimelineContentFilter.shared
@State private var scrollToIdAnimated: String? = nil
@State private var wasBackgrounded: Bool = false @State private var wasBackgrounded: Bool = false
@Binding var timeline: TimelineFilter @Binding var timeline: TimelineFilter
@ -45,9 +47,7 @@ public struct TimelineView: View {
public var body: some View { public var body: some View {
ZStack(alignment: .top) { ZStack(alignment: .top) {
listView listView
if viewModel.timeline.supportNewestPagination { statusesObserver
TimelineUnreadStatusesView(observer: viewModel.pendingStatusesObserver)
}
} }
.safeAreaInset(edge: .top, spacing: 0) { .safeAreaInset(edge: .top, spacing: 0) {
if canFilterTimeline, !pinnedFilters.isEmpty { if canFilterTimeline, !pinnedFilters.isEmpty {
@ -188,6 +188,14 @@ public struct TimelineView: View {
viewModel.scrollToId = nil viewModel.scrollToId = nil
} }
} }
.onChange(of: scrollToIdAnimated) { _, newValue in
if let newValue {
withAnimation {
proxy.scrollTo(newValue, anchor: .top)
scrollToIdAnimated = nil
}
}
}
.onChange(of: selectedTabScrollToTop) { _, newValue in .onChange(of: selectedTabScrollToTop) { _, newValue in
if newValue == 0, routerPath.path.isEmpty { if newValue == 0, routerPath.path.isEmpty {
withAnimation { withAnimation {
@ -198,6 +206,17 @@ public struct TimelineView: View {
} }
} }
@ViewBuilder
private var statusesObserver: some View {
if viewModel.timeline.supportNewestPagination {
TimelineUnreadStatusesView(observer: viewModel.pendingStatusesObserver) { statusId in
if let statusId {
scrollToIdAnimated = statusId
}
}
}
}
@ToolbarContentBuilder @ToolbarContentBuilder
private var toolbarTitleView: some ToolbarContent { private var toolbarTitleView: some ToolbarContent {
ToolbarItem(placement: .principal) { ToolbarItem(placement: .principal) {