mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-10 09:00:49 +01:00
Revert to using List for timeline and use infinite scrolling technique to speed up timeline loads
This commit is contained in:
parent
c6bd4cd6e3
commit
2292d04f91
@ -45,7 +45,6 @@ struct TimelineItemView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Divider()
|
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
articleIconImageLoader.loadImage(for: timelineItem.article)
|
articleIconImageLoader.loadImage(for: timelineItem.article)
|
||||||
|
@ -55,6 +55,14 @@ class TimelineModel: ObservableObject {
|
|||||||
fetchAndReplaceArticlesAsync()
|
fetchAndReplaceArticlesAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Replace this with ScrollViewReader if we have to keep it
|
||||||
|
func loadMoreTimelineItemsIfNecessary(_ timelineItem: TimelineItem) {
|
||||||
|
let thresholdIndex = timelineItems.index(timelineItems.endIndex, offsetBy: -10)
|
||||||
|
if timelineItems.firstIndex(where: { $0.id == timelineItem.id }) == thresholdIndex {
|
||||||
|
nextBatch()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
@ -112,11 +120,18 @@ private extension TimelineModel {
|
|||||||
|
|
||||||
func replaceArticles(with unsortedArticles: Set<Article>) {
|
func replaceArticles(with unsortedArticles: Set<Article>) {
|
||||||
articles = Array(unsortedArticles).sortedByDate(sortDirection ? .orderedDescending : .orderedAscending, groupByFeed: groupByFeed)
|
articles = Array(unsortedArticles).sortedByDate(sortDirection ? .orderedDescending : .orderedAscending, groupByFeed: groupByFeed)
|
||||||
timelineItems = articles.map { TimelineItem(article: $0) }
|
timelineItems = [TimelineItem]()
|
||||||
|
nextBatch()
|
||||||
// TODO: Update unread counts and other item done in didSet on AppKit
|
// TODO: Update unread counts and other item done in didSet on AppKit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func nextBatch() {
|
||||||
|
let rangeEndIndex = timelineItems.endIndex + 50 > articles.endIndex ? articles.endIndex : timelineItems.endIndex + 50
|
||||||
|
let range = timelineItems.endIndex..<rangeEndIndex
|
||||||
|
for i in range {
|
||||||
|
timelineItems.append(TimelineItem(article: articles[i]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Notifications
|
// MARK: - Notifications
|
||||||
|
|
||||||
|
@ -13,12 +13,11 @@ struct TimelineView: View {
|
|||||||
@EnvironmentObject private var timelineModel: TimelineModel
|
@EnvironmentObject private var timelineModel: TimelineModel
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
List(timelineModel.timelineItems) { timelineItem in
|
||||||
LazyVStack() {
|
TimelineItemView(timelineItem: timelineItem)
|
||||||
ForEach(timelineModel.timelineItems) { timelineItem in
|
.onAppear {
|
||||||
TimelineItemView(timelineItem: timelineItem)
|
timelineModel.loadMoreTimelineItemsIfNecessary(timelineItem)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user