Improvements on publish view.

This commit is contained in:
Marcin Czachursk 2023-02-18 14:17:18 +01:00
parent e60b78b1df
commit 7342c9f231
4 changed files with 73 additions and 42 deletions

View File

@ -33,6 +33,7 @@ struct ComposeView: View {
@State private var photosAreUploading = false
@State private var photosPickerVisible = false
@State private var showPhoto: PhotoAttachment? = nil
@State private var selectedItems: [PhotosPickerItem] = []
@State private var photosAttachment: [PhotoAttachment] = []
@ -94,9 +95,14 @@ struct ComposeView: View {
HStack(alignment: .center) {
ForEach(self.photosAttachment, id: \.id) { photoAttachment in
ImageUploadView(photoAttachment: photoAttachment) {
self.showPhoto = photoAttachment
} delete: {
self.photosAttachment = self.photosAttachment.filter({ item in
item != photoAttachment
})
self.publishDisabled = self.isPublishButtonDisabled()
self.interactiveDismissDisabled = self.isInteractiveDismissDisabled()
}
}
}
@ -133,7 +139,7 @@ struct ComposeView: View {
.frame(alignment: .topLeading)
.toolbar {
ToolbarItem(placement: .primaryAction) {
ActionButton {
ActionButton(showLoader: false) {
await self.publishStatus()
} label: {
Text("Publish")
@ -153,6 +159,9 @@ struct ComposeView: View {
await self.loadPhotos()
}
}
.sheet(item: $showPhoto, content: { item in
PhotoEditorView(photoAttachment: item)
})
.photosPicker(isPresented: $photosPickerVisible, selection: $selectedItems, maxSelectionCount: 4, matching: .images)
.navigationBarTitle(Text("Compose"), displayMode: .inline)
}

View File

@ -14,54 +14,61 @@ struct PhotoEditorView: View {
@ObservedObject public var photoAttachment: PhotoAttachment
var body: some View {
VStack(alignment: .leading) {
if let uiImage = UIImage(data: photoAttachment.photoData) {
List {
Section(header: Text("Photo")) {
HStack {
Spacer()
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
.frame(maxHeight: 300)
Spacer()
NavigationView {
VStack(alignment: .leading) {
if let uiImage = UIImage(data: photoAttachment.photoData) {
List {
Section(header: Text("Photo")) {
HStack {
Spacer()
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
.frame(maxHeight: 300)
Spacer()
}
}
}
Section(header: Text("Accessibility")) {
TextField("Sescription for the visually impaired", text: $description, axis: .vertical)
.keyboardType(.default)
.lineLimit(2...5)
.multilineTextAlignment(.leading)
}
}.listStyle(.grouped)
Section(header: Text("Accessibility")) {
TextField("Sescription for the visually impaired", text: $description, axis: .vertical)
.keyboardType(.default)
.lineLimit(2...5)
.multilineTextAlignment(.leading)
}
}.listStyle(.grouped)
Spacer()
Spacer()
}
}
.onDisappear {
self.hideKeyboard()
}
.onAppear {
self.description = self.photoAttachment.uploadedAttachment?.description ?? String.empty()
}
.navigationBarTitle(Text("Photo details"), displayMode: .inline)
.toolbar {
self.getTrailingToolbar()
}
}
.onDisappear {
self.hideKeyboard()
}
.onAppear {
self.description = self.photoAttachment.uploadedAttachment?.description ?? String.empty()
}
.navigationBarTitle("Photo details")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
self.getTrailingToolbar()
}
}
@ToolbarContentBuilder
private func getTrailingToolbar() -> some ToolbarContent {
ToolbarItem(placement: .navigationBarTrailing) {
ActionButton {
ActionButton(showLoader: false) {
await self.update()
} label: {
Text("Update")
}.buttonStyle(.borderedProminent)
}
ToolbarItem(placement: .cancellationAction) {
Button("Cancel", role: .cancel) {
dismiss()
}
}
}
private func update() async {

View File

@ -7,14 +7,16 @@
import SwiftUI
struct ActionButton<Label>: View where Label: View {
@State public var showLoader: Bool
@State private var isDuringAction = false
private let action: () async -> Void
private let label: () -> Label
public init(action: @escaping () async -> Void, @ViewBuilder label: @escaping () -> Label) {
public init(showLoader: Bool = true, action: @escaping () async -> Void, @ViewBuilder label: @escaping () -> Label) {
self.action = action
self.label = label
self.showLoader = showLoader
}
var body: some View {
@ -32,14 +34,23 @@ struct ActionButton<Label>: View where Label: View {
}
}
} label: {
if isDuringAction {
LoadingIndicator(isVisible: .constant(true))
.transition(.opacity)
if self.showLoader {
withLoader()
} else {
label()
.transition(.opacity)
}
}.disabled(isDuringAction)
}
@ViewBuilder
private func withLoader() -> some View {
if isDuringAction {
LoadingIndicator(isVisible: .constant(true))
.transition(.opacity)
} else {
label()
.transition(.opacity)
}
}
}

View File

@ -11,10 +11,12 @@ struct ImageUploadView: View {
@ObservedObject public var photoAttachment: PhotoAttachment
private let delete: () -> Void
private let open: () -> Void
public init(photoAttachment: PhotoAttachment, delete: @escaping () -> Void) {
public init(photoAttachment: PhotoAttachment, open: @escaping () -> Void, delete: @escaping () -> Void) {
self.photoAttachment = photoAttachment
self.delete = delete
self.open = open
}
var body: some View {
@ -51,7 +53,9 @@ struct ImageUploadView: View {
}
} else {
Menu {
NavigationLink(value: RouteurDestinations.photoEditor(photoAttachment: photoAttachment)) {
Button {
self.open()
} label: {
Label("Edit", systemImage: "pencil")
}