Impressia/Vernissage/Widgets/BlurredImage.swift

29 lines
706 B
Swift
Raw Normal View History

2023-01-09 14:48:41 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-01-09 14:48:41 +01:00
//
import SwiftUI
struct BlurredImage: View {
@State var blurhash: String?
2023-03-05 13:58:22 +01:00
private let defaultBlurhash = "LFC6ZCso00OZ~q%29FNHE2tRr=RP"
2023-01-09 14:48:41 +01:00
var body: some View {
2023-03-05 13:58:22 +01:00
if let blurhash, let uiImage = UIImage(blurHash: blurhash, size: CGSize(width: 32, height: 32)) {
2023-01-09 14:48:41 +01:00
Image(uiImage: uiImage)
.resizable()
} else {
2023-03-05 13:58:22 +01:00
Image("Blurhash")
.resizable()
2023-01-09 14:48:41 +01:00
}
}
}
struct BlurredImage_Previews: PreviewProvider {
static var previews: some View {
BlurredImage()
}
}