IceCubesApp/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift

45 lines
1.2 KiB
Swift
Raw Normal View History

2022-12-17 12:37:46 +00:00
import SwiftUI
import Models
public struct StatusMediaPreviewView: View {
public let attachements: [MediaAttachement]
public var body: some View {
VStack {
HStack {
if let firstAttachement = attachements.first {
makePreviewImage(attachement: firstAttachement)
}
if attachements.count > 1, let secondAttachement = attachements[1] {
makePreviewImage(attachement: secondAttachement)
}
}
HStack {
if attachements.count > 2, let secondAttachement = attachements[2] {
makePreviewImage(attachement: secondAttachement)
}
if attachements.count > 3, let secondAttachement = attachements[3] {
makePreviewImage(attachement: secondAttachement)
}
}
}
}
private func makePreviewImage(attachement: MediaAttachement) -> some View {
AsyncImage(
url: attachement.url,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fill)
2022-12-18 19:30:19 +00:00
.frame(maxHeight: attachements.count > 2 ? 100 : 200)
2022-12-17 12:37:46 +00:00
.clipped()
.cornerRadius(4)
},
placeholder: {
ProgressView()
.frame(maxWidth: 80, maxHeight: 80)
}
)
}
}