mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Use ImageManager of SDWebImageSwiftUI
This commit is contained in:
37
Shared/Videos/ThumbnailView.swift
Normal file
37
Shared/Videos/ThumbnailView.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ThumbnailView: View {
|
||||
var url: URL?
|
||||
|
||||
@ObservedObject private var imageManager = ImageManager()
|
||||
private var thumbnails = ThumbnailsModel.shared
|
||||
|
||||
init(url: URL? = nil) {
|
||||
self.url = url
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if imageManager.image != nil {
|
||||
#if os(macOS)
|
||||
Image(nsImage: imageManager.image!)
|
||||
.resizable()
|
||||
#else
|
||||
Image(uiImage: imageManager.image!)
|
||||
.resizable()
|
||||
#endif
|
||||
} else {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
.onAppear {
|
||||
self.imageManager.setOnFailure { _ in
|
||||
guard let url else { return }
|
||||
self.thumbnails.insertUnloadable(url)
|
||||
}
|
||||
self.imageManager.load(url: url)
|
||||
}
|
||||
.onDisappear { self.imageManager.cancel() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -131,8 +131,7 @@ struct VideoBanner: View {
|
||||
Color("PlaceholderColor")
|
||||
if let video {
|
||||
if let thumbnail = video.thumbnailURL(quality: .medium) {
|
||||
WebImage(url: thumbnail, options: [.lowPriority])
|
||||
.resizable()
|
||||
ThumbnailView(url: thumbnail)
|
||||
} else if video.isLocal {
|
||||
Image(systemName: video.localStreamImageSystemName)
|
||||
}
|
||||
|
@@ -421,18 +421,7 @@ struct VideoCell: View {
|
||||
|
||||
private var thumbnailImage: some View {
|
||||
Group {
|
||||
let url = thumbnails.best(video)
|
||||
|
||||
WebImage(url: url, options: [.lowPriority])
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().foregroundColor(Color("PlaceholderColor"))
|
||||
}
|
||||
.retryOnAppear(true)
|
||||
.onFailure { _ in
|
||||
guard let url else { return }
|
||||
thumbnails.insertUnloadable(url)
|
||||
}
|
||||
ThumbnailView(url: thumbnails.best(video))
|
||||
|
||||
#if os(tvOS)
|
||||
.frame(minHeight: 320)
|
||||
|
Reference in New Issue
Block a user