Skip to content

Commit

Permalink
Restore tap on status counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Sep 19, 2024
1 parent db71554 commit 12b6c1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import SwiftUI
}

struct TimelineUnreadStatusesView: View {
@State var observer: TimelineUnreadStatusesObserver
@Environment(UserPreferences.self) private var preferences
@Environment(Theme.self) private var theme

@State var observer: TimelineUnreadStatusesObserver
let onButtonTap: (String?) -> Void

var body: some View {
if observer.pendingStatusesCount > 0 || observer.isLoadingNewStatuses {
Button { } label: {
Button {
onButtonTap(observer.pendingStatuses.last)
} label: {
HStack(spacing: 8) {
if observer.isLoadingNewStatuses {
ProgressView()
Expand Down
25 changes: 22 additions & 3 deletions Packages/Timeline/Sources/Timeline/View/TimelineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public struct TimelineView: View {

@State private var viewModel = TimelineViewModel()
@State private var contentFilter = TimelineContentFilter.shared

@State private var scrollToIdAnimated: String? = nil

@State private var wasBackgrounded: Bool = false

Expand All @@ -45,9 +47,7 @@ public struct TimelineView: View {
public var body: some View {
ZStack(alignment: .top) {
listView
if viewModel.timeline.supportNewestPagination {
TimelineUnreadStatusesView(observer: viewModel.pendingStatusesObserver)
}
statusesObserver
}
.safeAreaInset(edge: .top, spacing: 0) {
if canFilterTimeline, !pinnedFilters.isEmpty {
Expand Down Expand Up @@ -188,6 +188,14 @@ public struct TimelineView: View {
viewModel.scrollToId = nil
}
}
.onChange(of: scrollToIdAnimated) { _, newValue in
if let newValue {
withAnimation {
proxy.scrollTo(newValue, anchor: .top)
scrollToIdAnimated = nil
}
}
}
.onChange(of: selectedTabScrollToTop) { _, newValue in
if newValue == 0, routerPath.path.isEmpty {
withAnimation {
Expand All @@ -197,6 +205,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
private var toolbarTitleView: some ToolbarContent {
Expand Down

0 comments on commit 12b6c1a

Please sign in to comment.