Various optimizations for the new timeline

This commit is contained in:
Thomas Ricouard 2023-02-01 09:22:08 +01:00
parent 83049517c0
commit 9bf40b262f
3 changed files with 5 additions and 5 deletions

View file

@ -28,7 +28,7 @@ class PendingStatusesObserver: ObservableObject {
struct PendingStatusesObserverView: View {
@ObservedObject var observer: PendingStatusesObserver
@State var proxy: ScrollViewProxy
var proxy: ScrollViewProxy
var body: some View {
if observer.pendingStatusesCount > 0 {
@ -36,7 +36,7 @@ struct PendingStatusesObserverView: View {
Spacer()
Button {
withAnimation {
proxy.scrollTo(observer.pendingStatuses.last, anchor: .bottom)
proxy.scrollTo(observer.pendingStatuses.last, anchor: .top)
}
} label: {
Text("\(observer.pendingStatusesCount)")

View file

@ -48,7 +48,7 @@ public struct TimelineView: View {
StatusesListView(fetcher: viewModel)
}
}
.id(account.account?.id)
.id(account.account?.id ?? client.id)
.environment(\.defaultMinListRowHeight, 1)
.listStyle(.plain)
.scrollContentBackground(.hidden)

View file

@ -70,7 +70,7 @@ class TimelineViewModel: ObservableObject, StatusesFetcher {
}
} else if let first = statuses.first {
canStreamEvents = false
var newStatuses: [Status] = await fetchNewPages(minId: first.id, maxPages: 20)
var newStatuses: [Status] = await fetchNewPages(minId: first.id, maxPages: 10)
if !pendingStatusesEnabled {
statuses.insert(contentsOf: newStatuses, at: 0)
pendingStatusesObserver.pendingStatuses = []
@ -98,7 +98,7 @@ class TimelineViewModel: ObservableObject, StatusesFetcher {
withAnimation {
statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
self.scrollProxy?.scrollTo(firstStatusId)
self.scrollProxy?.scrollTo(firstStatusId, anchor: .top)
self.pendingStatusesObserver.disableUpdate = false
self.canStreamEvents = true
}