diff options
Diffstat (limited to 'Jel/Views/Utility/AsyncImageView.swift')
-rw-r--r-- | Jel/Views/Utility/AsyncImageView.swift | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Jel/Views/Utility/AsyncImageView.swift b/Jel/Views/Utility/AsyncImageView.swift new file mode 100644 index 0000000..bed5687 --- /dev/null +++ b/Jel/Views/Utility/AsyncImageView.swift @@ -0,0 +1,50 @@ +// +// AsyncImageView.swift +// Jel +// +// Created by zerocool on 12/19/23. +// + +import SwiftUI +import BlurHashKit +import JellyfinKit + +struct AsyncImageView: View { + @EnvironmentObject var jellyfinClient: JellyfinClientController + + @State var imageId: String + @State var blurhash: String + @State var imageType: String + + @State var loading = true + @State var uiImage: UIImage = UIImage() + + var body: some View { + VStack { + if loading { + BlurHashView(blurHash: blurhash) + } else { + Image(uiImage: uiImage) + } + } + .onAppear { + Task { + let request = Paths.getItemImage(itemID: imageId, imageType: imageType) + do { + let res = try await jellyfinClient.send(request) + if let image = UIImage(data: res.value) { + uiImage = image + loading = false + } else { + + } + } + } + + } + } +} + +//#Preview { +// AsyncImageView(imageId: "", blurhash: "", imageType: "") +//} |