Fix flicker in feed

This commit is contained in:
Arkadiusz Fal 2022-12-13 20:15:00 +01:00
parent e390bbcf09
commit 0517b4feea

View File

@ -17,59 +17,25 @@ struct FeedView: View {
} }
var body: some View { var body: some View {
VerticalCells(items: videos) { VerticalCells(items: videos) { if shouldDisplayHeader { header } }
HStack { .environment(\.loadMoreContentHandler) { feed.loadNextPage() }
#if os(tvOS) .onAppear {
SubscriptionsPageButton() feed.loadResources()
ListingStyleButtons(listingStyle: $subscriptionsListingStyle) }
#endif .onChange(of: accounts.current) { _ in
feed.reset()
if showCacheStatus { feed.loadResources(force: true)
Spacer()
CacheStatusHeader(
refreshTime: feed.formattedFeedTime,
isLoading: feed.isLoading
)
}
#if os(tvOS)
if !showCacheStatus {
Spacer()
}
Button {
feed.loadResources(force: true)
} label: {
Label("Refresh", systemImage: "arrow.clockwise")
.labelStyle(.iconOnly)
.imageScale(.small)
.font(.caption2)
}
#endif
} }
.padding(.leading, 30)
#if os(tvOS)
.padding(.bottom, 15)
#endif
}
.environment(\.loadMoreContentHandler) { feed.loadNextPage() }
.onAppear {
feed.loadResources()
}
.onChange(of: accounts.current) { _ in
feed.reset()
feed.loadResources(force: true)
}
#if os(iOS) #if os(iOS)
.refreshControl { refreshControl in .refreshControl { refreshControl in
feed.loadResources(force: true) { feed.loadResources(force: true) {
refreshControl.endRefreshing() refreshControl.endRefreshing()
}
}
.backport
.refreshable {
await feed.loadResources(force: true)
} }
}
.backport
.refreshable {
await feed.loadResources(force: true)
}
#endif #endif
#if !os(tvOS) #if !os(tvOS)
.background( .background(
@ -86,6 +52,50 @@ struct FeedView: View {
} }
#endif #endif
} }
var header: some View {
HStack {
#if os(tvOS)
SubscriptionsPageButton()
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
#endif
if showCacheStatus {
Spacer()
CacheStatusHeader(
refreshTime: feed.formattedFeedTime,
isLoading: feed.isLoading
)
}
#if os(tvOS)
if !showCacheStatus {
Spacer()
}
Button {
feed.loadResources(force: true)
} label: {
Label("Refresh", systemImage: "arrow.clockwise")
.labelStyle(.iconOnly)
.imageScale(.small)
.font(.caption2)
}
#endif
}
.padding(.leading, 30)
#if os(tvOS)
.padding(.bottom, 15)
#endif
}
var shouldDisplayHeader: Bool {
#if os(tvOS)
true
#else
showCacheStatus
#endif
}
} }
struct SubscriptonsView_Previews: PreviewProvider { struct SubscriptonsView_Previews: PreviewProvider {