Impressia/Vernissage/Views/DetailsView.swift

129 lines
5.0 KiB
Swift
Raw Normal View History

2022-12-29 17:27:15 +01:00
//
// https://mczachurski.dev
// Copyright © 2022 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
import MastodonSwift
2023-01-02 19:12:25 +01:00
import AVFoundation
2022-12-29 17:27:15 +01:00
struct DetailsView: View {
@Environment(\.dismiss) private var dismiss
2023-01-02 19:12:25 +01:00
2023-01-01 18:13:36 +01:00
@State public var statusData: StatusData
2023-01-02 19:12:25 +01:00
@State private var height: Double = 0.0
2022-12-29 17:27:15 +01:00
var body: some View {
ScrollView {
VStack (alignment: .leading) {
2023-01-02 19:12:25 +01:00
TabView {
ForEach(statusData.attachments(), id: \.self) { attachment in
if let image = UIImage(data: attachment.data) {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fit)
}
}
2023-01-01 18:13:36 +01:00
}
2023-01-02 19:12:25 +01:00
.frame(height: CGFloat(self.height))
.tabViewStyle(PageTabViewStyle())
2022-12-29 17:27:15 +01:00
VStack(alignment: .leading) {
HStack (alignment: .center) {
2023-01-01 18:13:36 +01:00
AsyncImage(url: statusData.accountAvatar) { image in
2022-12-29 17:27:15 +01:00
image
.resizable()
.clipShape(Circle())
.aspectRatio(contentMode: .fit)
} placeholder: {
Image(systemName: "person.circle")
.resizable()
2022-12-31 16:31:05 +01:00
.foregroundColor(Color("mainTextColor"))
2022-12-29 17:27:15 +01:00
}
2022-12-31 16:31:05 +01:00
.frame(width: 48.0, height: 48.0)
2022-12-29 17:27:15 +01:00
VStack (alignment: .leading) {
2023-01-01 18:13:36 +01:00
Text(statusData.accountDisplayName ?? statusData.accountUsername)
2022-12-29 17:27:15 +01:00
.foregroundColor(Color("displayNameColor"))
2023-01-01 18:13:36 +01:00
Text("@\(statusData.accountUsername)")
2022-12-29 17:27:15 +01:00
.foregroundColor(Color("lightGrayColor"))
.font(.footnote)
}
.padding(.leading, 8)
}
2023-01-01 18:13:36 +01:00
HTMLFormattedText(statusData.content)
2022-12-29 17:27:15 +01:00
VStack (alignment: .leading) {
LabelIconView(iconName: "camera", value: "SONY ILCE-7M3")
LabelIconView(iconName: "camera.aperture", value: "Viltrox 24mm F1.8 E")
LabelIconView(iconName: "timelapse", value: "24.0 mm, f/1.8, 1/640s, ISO 100")
LabelIconView(iconName: "calendar", value: "2 Oct 2022")
}
.foregroundColor(Color("lightGrayColor"))
HStack (alignment: .top) {
TagView {
// Favorite
} content: {
HStack {
2023-01-01 18:13:36 +01:00
Image(systemName: statusData.favourited ? "heart.fill" : "heart")
Text("\(statusData.favouritesCount) likes")
2022-12-29 17:27:15 +01:00
}
}
TagView {
// Reboost
} content: {
HStack {
2023-01-01 18:13:36 +01:00
Image(systemName: statusData.reblogged ? "arrowshape.turn.up.forward.fill" : "arrowshape.turn.up.forward")
Text("\(statusData.reblogsCount) boosts")
2022-12-29 17:27:15 +01:00
}
}
Spacer()
TagView {
// Bookmark
} content: {
2023-01-01 18:13:36 +01:00
Image(systemName: statusData.bookmarked ? "bookmark.fill" : "bookmark")
2022-12-29 17:27:15 +01:00
}
}
.font(.subheadline)
.foregroundColor(Color("mainTextColor"))
}
.padding(8)
}
}
2022-12-30 18:20:54 +01:00
.navigationBarTitle("Details")
2023-01-02 19:12:25 +01:00
.onAppear {
self.calculateImageHeight()
}
}
private func calculateImageHeight() {
var imageHeight = 0.0
var imageWidth = 0.0
for item in statusData.attachments() {
if let image = UIImage(data: item.data) {
if image.size.height > imageHeight {
imageHeight = image.size.height
imageWidth = image.size.width
}
}
}
let divider = imageWidth / UIScreen.main.bounds.size.width
self.height = imageHeight / divider
2022-12-29 17:27:15 +01:00
}
}
struct DetailsView_Previews: PreviewProvider {
static var previews: some View {
Text("")
// DetailsView(current: ImageStatus(id: "123", image: UIImage(), status: Status(from: <#T##Decoder#>)))
}
}