Impressia/Vernissage/Widgets/ImageRow.swift

52 lines
1.6 KiB
Swift
Raw Normal View History

2023-01-03 14:09:22 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
struct ImageRow: View {
2023-01-09 14:48:41 +01:00
@State public var status: StatusData
@State private var showSensitive = false
2023-01-03 14:09:22 +01:00
var body: some View {
2023-01-09 14:48:41 +01:00
if let attachmenData = self.status.attachments().first,
2023-01-03 14:09:22 +01:00
let uiImage = UIImage(data: attachmenData.data) {
ZStack {
2023-01-09 14:48:41 +01:00
if self.status.sensitive {
ContentWarning(blurhash: attachmenData.blurhash, spoilerText: self.status.spoilerText) {
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
.transition(.opacity)
}
} else {
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
}
2023-01-03 14:09:22 +01:00
2023-01-09 14:48:41 +01:00
if let count = self.status.attachments().count, count > 1 {
2023-01-03 14:09:22 +01:00
BottomRight {
Text("1 / \(count)")
.padding(.horizontal, 6)
.padding(.vertical, 3)
.font(.caption2)
.foregroundColor(.black)
.background(.ultraThinMaterial, in: Capsule())
}.padding()
}
}
}
}
}
struct ImageRow_Previews: PreviewProvider {
static var previews: some View {
2023-01-09 14:48:41 +01:00
Text("")
// ImageRow(status: [])
2023-01-03 14:09:22 +01:00
}
}