Impressia/Vernissage/Views/PhotoEditorView.swift

71 lines
2.3 KiB
Swift
Raw Normal View History

2023-02-17 14:47:59 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
struct PhotoEditorView: View {
2023-02-17 17:10:09 +01:00
@Environment(\.dismiss) private var dismiss
2023-02-17 14:47:59 +01:00
2023-02-17 17:10:09 +01:00
@State private var description: String = String.empty()
@ObservedObject public var photoAttachment: PhotoAttachment
2023-02-17 14:47:59 +01:00
var body: some View {
VStack(alignment: .leading) {
if let uiImage = UIImage(data: photoAttachment.photoData) {
2023-02-18 12:02:49 +01:00
List {
2023-02-18 11:47:49 +01:00
Section(header: Text("Photo")) {
HStack {
Spacer()
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
2023-02-18 12:02:49 +01:00
.clipShape(RoundedRectangle(cornerRadius: 10))
2023-02-18 11:47:49 +01:00
.frame(maxHeight: 300)
Spacer()
}
}
2023-02-17 17:10:09 +01:00
2023-02-18 11:47:49 +01:00
Section(header: Text("Accessibility")) {
2023-02-18 12:02:49 +01:00
TextField("Sescription for the visually impaired", text: $description, axis: .vertical)
2023-02-18 11:47:49 +01:00
.keyboardType(.default)
2023-02-18 12:02:49 +01:00
.lineLimit(2...5)
2023-02-18 11:47:49 +01:00
.multilineTextAlignment(.leading)
}
2023-02-18 12:02:49 +01:00
}.listStyle(.grouped)
2023-02-17 14:47:59 +01:00
2023-02-18 11:47:49 +01:00
Spacer()
}
}
.onDisappear {
self.hideKeyboard()
2023-02-17 14:47:59 +01:00
}
2023-02-17 17:10:09 +01:00
.onAppear {
self.description = self.photoAttachment.description
}
2023-02-18 11:47:49 +01:00
.navigationBarTitle("Photo details")
2023-02-17 17:10:09 +01:00
.navigationBarTitleDisplayMode(.inline)
.toolbar {
self.getTrailingToolbar()
}
}
@ToolbarContentBuilder
private func getTrailingToolbar() -> some ToolbarContent {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
HapticService.shared.touch()
self.photoAttachment.description = self.description
2023-02-18 11:47:49 +01:00
self.hideKeyboard()
2023-02-17 17:10:09 +01:00
self.dismiss()
} label: {
Text("Update")
}.buttonStyle(.borderedProminent)
}
2023-02-17 14:47:59 +01:00
}
}
2023-02-17 17:10:09 +01:00