Impressia/Vernissage/Widgets/ImageGrid.swift

61 lines
2.0 KiB
Swift
Raw Normal View History

//
// 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.
//
import SwiftUI
import NukeUI
struct ImageGrid: View {
2023-03-05 13:58:22 +01:00
@EnvironmentObject var applicationState: ApplicationState
@EnvironmentObject var routerPath: RouterPath
2023-03-14 18:45:41 +01:00
@StateObject var photoUrl: PhotoUrl
2023-03-14 18:45:41 +01:00
@State var maxHeight = 120.0
var body: some View {
2023-03-05 13:58:22 +01:00
if self.photoUrl.sensitive && !self.applicationState.showSensitive {
BlurredImage(blurhash: self.photoUrl.blurhash)
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
.onTapGesture {
if let statusId = self.photoUrl.statusId {
self.routerPath.navigate(to: .status(id: statusId))
}
}
} else if let url = photoUrl.url {
LazyImage(url: url) { state in
if let image = state.image {
image
.resizable()
2023-03-14 18:45:41 +01:00
.aspectRatio(contentMode: .fill)
.frame(width: self.maxHeight, height: self.maxHeight)
2023-03-04 19:35:59 +01:00
.clipShape(RoundedRectangle(cornerRadius: 10))
2023-03-14 18:45:41 +01:00
.clipped()
.onTapGesture {
if let statusId = self.photoUrl.statusId {
self.routerPath.navigate(to: .status(id: statusId))
}
}
} else if state.isLoading {
2023-03-04 19:35:59 +01:00
self.placeholder()
} else {
2023-03-04 19:35:59 +01:00
self.placeholder()
}
}
.priority(.high)
} else {
self.placeholder()
}
}
@ViewBuilder
private func placeholder() -> some View {
2023-03-04 19:35:59 +01:00
Image("ImagePlaceholder")
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
}