blob: bed5687d8fef8227455b465e3e60abf0583d8e70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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: "")
//}
|