Impressia/Vernissage/Widgets/ImageGrid.swift

46 lines
1.3 KiB
Swift
Raw Normal View History

//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
import NukeUI
struct ImageGrid: View {
@EnvironmentObject var routerPath: RouterPath
@StateObject var photoUrl: PhotoUrl
2023-03-04 19:35:59 +01:00
var body: some View {
if let url = photoUrl.url {
LazyImage(url: url) { state in
if let image = state.image {
image
.aspectRatio(contentMode: .fit)
2023-03-04 19:35:59 +01:00
.clipShape(RoundedRectangle(cornerRadius: 10))
.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))
}
}