Channels performance improvements

Add settings:
Show channel avatars in channels lists
Show channel avatars in videos lists

Fix #508
This commit is contained in:
Arkadiusz Fal
2023-07-22 19:02:59 +02:00
parent 37a96a01db
commit 3c9e04d243
14 changed files with 81 additions and 71 deletions

View File

@@ -9,11 +9,13 @@ struct ChannelAvatarView: View {
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var subscribedChannels = SubscribedChannelsModel.shared
@State private var url: URL?
var body: some View {
ZStack(alignment: .bottomTrailing) {
Group {
Group {
if let url = channel?.thumbnailURLOrCached {
if let url {
ThumbnailView(url: url)
} else {
ZStack {
@@ -31,6 +33,7 @@ struct ChannelAvatarView: View {
.font(.system(size: 20))
.contentShape(Rectangle())
}
.onAppear(perform: updateURL)
}
}
.clipShape(Circle())
@@ -54,6 +57,16 @@ struct ChannelAvatarView: View {
}
.imageScale(.small)
}
func updateURL() {
DispatchQueue.global(qos: .userInitiated).async {
if let url = channel?.thumbnailURLOrCached {
DispatchQueue.main.async {
self.url = url
}
}
}
}
}
struct ChannelAvatarView_Previews: PreviewProvider {

View File

@@ -61,7 +61,8 @@ struct ChannelListItem: View {
private var label: some View {
HStack(alignment: .top, spacing: 12) {
VStack {
ChannelAvatarView(channel: channel)
ChannelAvatarView(channel: channel, subscribedBadge: false)
.id("channel-avatar-\(channel.id)")
#if os(tvOS)
.frame(width: 90, height: 90)
#else

View File

@@ -205,6 +205,7 @@ struct ChannelVideosView: View {
var thumbnail: some View {
ChannelAvatarView(channel: store.item?.channel)
.id("channel-avatar-\(store.item?.channel?.id ?? "")")
#if os(tvOS)
.frame(width: 80, height: 80, alignment: .trailing)
#else