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 {
VerticalCells(items: videos) {
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
VerticalCells(items: videos) { if shouldDisplayHeader { header } }
.environment(\.loadMoreContentHandler) { feed.loadNextPage() }
.onAppear {
feed.loadResources()
}
.onChange(of: accounts.current) { _ in
feed.reset()
feed.loadResources(force: true)
}
.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)
.refreshControl { refreshControl in
feed.loadResources(force: true) {
refreshControl.endRefreshing()
.refreshControl { refreshControl in
feed.loadResources(force: true) {
refreshControl.endRefreshing()
}
}
.backport
.refreshable {
await feed.loadResources(force: true)
}
}
.backport
.refreshable {
await feed.loadResources(force: true)
}
#endif
#if !os(tvOS)
.background(
@ -86,6 +52,50 @@ struct FeedView: View {
}
#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 {