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

66 lines
1.6 KiB
Swift
Raw Normal View History

2022-12-19 16:18:16 +00:00
import SwiftUI
import Models
2022-12-22 18:00:23 +00:00
import Shimmer
2022-12-19 16:18:16 +00:00
public struct StatusCardView: View {
2022-12-19 16:18:16 +00:00
@Environment(\.openURL) private var openURL
let card: Card
2022-12-19 16:18:16 +00:00
public init(card: Card) {
self.card = card
}
public var body: some View {
if let title = card.title {
2022-12-19 16:18:16 +00:00
VStack(alignment: .leading) {
if let imageURL = card.image {
AsyncImage(
url: imageURL,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fill)
2022-12-20 07:14:57 +00:00
.frame(maxHeight: 200)
.clipped()
2022-12-19 16:18:16 +00:00
},
placeholder: {
2022-12-22 18:00:23 +00:00
Rectangle()
.fill(Color.gray)
.frame(height: 200)
.shimmering()
2022-12-19 16:18:16 +00:00
}
)
}
Spacer()
HStack {
VStack(alignment: .leading, spacing: 6) {
Text(title)
.font(.headline)
.lineLimit(3)
if let description = card.description, !description.isEmpty {
Text(description)
.font(.body)
.foregroundColor(.gray)
.lineLimit(3)
} else {
Text(card.url.absoluteString)
.font(.body)
.foregroundColor(.gray)
.lineLimit(3)
}
}
Spacer()
}.padding(8)
}
.background(Color.gray.opacity(0.15))
.cornerRadius(16)
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(.gray.opacity(0.35), lineWidth: 1)
)
.onTapGesture {
openURL(card.url)
}
}
}
}