42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
//
|
|
/*
|
|
* SwiftFin is subject to the terms of the Mozilla Public
|
|
* License, v2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
|
|
*/
|
|
|
|
import SwiftUI
|
|
import NukeUI
|
|
|
|
struct ImageView: View {
|
|
private let source: URL
|
|
private let blurhash: String
|
|
private let failureInitials: String
|
|
|
|
init(src: URL, bh: String = "001fC^", failureInitials: String = "") {
|
|
self.source = src
|
|
self.blurhash = bh
|
|
self.failureInitials = failureInitials
|
|
}
|
|
|
|
var body: some View {
|
|
LazyImage(source: source)
|
|
.placeholder {
|
|
Image(uiImage: UIImage(blurHash: blurhash, size: CGSize(width: 8, height: 8)) ?? UIImage(blurHash: "001fC^", size: CGSize(width: 8, height: 8))!)
|
|
.resizable()
|
|
}
|
|
.failure {
|
|
ZStack {
|
|
Rectangle()
|
|
.foregroundColor(Color(UIColor.systemFill))
|
|
|
|
Text(failureInitials)
|
|
.font(.largeTitle)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
}
|
|
}
|