Improvements on publish view.
This commit is contained in:
parent
e60b78b1df
commit
7342c9f231
|
@ -33,6 +33,7 @@ struct ComposeView: View {
|
||||||
|
|
||||||
@State private var photosAreUploading = false
|
@State private var photosAreUploading = false
|
||||||
@State private var photosPickerVisible = false
|
@State private var photosPickerVisible = false
|
||||||
|
@State private var showPhoto: PhotoAttachment? = nil
|
||||||
|
|
||||||
@State private var selectedItems: [PhotosPickerItem] = []
|
@State private var selectedItems: [PhotosPickerItem] = []
|
||||||
@State private var photosAttachment: [PhotoAttachment] = []
|
@State private var photosAttachment: [PhotoAttachment] = []
|
||||||
|
@ -94,9 +95,14 @@ struct ComposeView: View {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
ForEach(self.photosAttachment, id: \.id) { photoAttachment in
|
ForEach(self.photosAttachment, id: \.id) { photoAttachment in
|
||||||
ImageUploadView(photoAttachment: photoAttachment) {
|
ImageUploadView(photoAttachment: photoAttachment) {
|
||||||
|
self.showPhoto = photoAttachment
|
||||||
|
} delete: {
|
||||||
self.photosAttachment = self.photosAttachment.filter({ item in
|
self.photosAttachment = self.photosAttachment.filter({ item in
|
||||||
item != photoAttachment
|
item != photoAttachment
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.publishDisabled = self.isPublishButtonDisabled()
|
||||||
|
self.interactiveDismissDisabled = self.isInteractiveDismissDisabled()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +139,7 @@ struct ComposeView: View {
|
||||||
.frame(alignment: .topLeading)
|
.frame(alignment: .topLeading)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .primaryAction) {
|
ToolbarItem(placement: .primaryAction) {
|
||||||
ActionButton {
|
ActionButton(showLoader: false) {
|
||||||
await self.publishStatus()
|
await self.publishStatus()
|
||||||
} label: {
|
} label: {
|
||||||
Text("Publish")
|
Text("Publish")
|
||||||
|
@ -153,6 +159,9 @@ struct ComposeView: View {
|
||||||
await self.loadPhotos()
|
await self.loadPhotos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(item: $showPhoto, content: { item in
|
||||||
|
PhotoEditorView(photoAttachment: item)
|
||||||
|
})
|
||||||
.photosPicker(isPresented: $photosPickerVisible, selection: $selectedItems, maxSelectionCount: 4, matching: .images)
|
.photosPicker(isPresented: $photosPickerVisible, selection: $selectedItems, maxSelectionCount: 4, matching: .images)
|
||||||
.navigationBarTitle(Text("Compose"), displayMode: .inline)
|
.navigationBarTitle(Text("Compose"), displayMode: .inline)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,54 +14,61 @@ struct PhotoEditorView: View {
|
||||||
@ObservedObject public var photoAttachment: PhotoAttachment
|
@ObservedObject public var photoAttachment: PhotoAttachment
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
NavigationView {
|
||||||
if let uiImage = UIImage(data: photoAttachment.photoData) {
|
VStack(alignment: .leading) {
|
||||||
List {
|
if let uiImage = UIImage(data: photoAttachment.photoData) {
|
||||||
Section(header: Text("Photo")) {
|
List {
|
||||||
HStack {
|
Section(header: Text("Photo")) {
|
||||||
Spacer()
|
HStack {
|
||||||
Image(uiImage: uiImage)
|
Spacer()
|
||||||
.resizable()
|
Image(uiImage: uiImage)
|
||||||
.aspectRatio(contentMode: .fit)
|
.resizable()
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
.aspectRatio(contentMode: .fit)
|
||||||
.frame(maxHeight: 300)
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||||
Spacer()
|
.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")) {
|
Spacer()
|
||||||
TextField("Sescription for the visually impaired", text: $description, axis: .vertical)
|
}
|
||||||
.keyboardType(.default)
|
}
|
||||||
.lineLimit(2...5)
|
.onDisappear {
|
||||||
.multilineTextAlignment(.leading)
|
self.hideKeyboard()
|
||||||
}
|
}
|
||||||
}.listStyle(.grouped)
|
.onAppear {
|
||||||
|
self.description = self.photoAttachment.uploadedAttachment?.description ?? String.empty()
|
||||||
Spacer()
|
}
|
||||||
|
.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
|
@ToolbarContentBuilder
|
||||||
private func getTrailingToolbar() -> some ToolbarContent {
|
private func getTrailingToolbar() -> some ToolbarContent {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
ActionButton {
|
ActionButton(showLoader: false) {
|
||||||
await self.update()
|
await self.update()
|
||||||
} label: {
|
} label: {
|
||||||
Text("Update")
|
Text("Update")
|
||||||
}.buttonStyle(.borderedProminent)
|
}.buttonStyle(.borderedProminent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button("Cancel", role: .cancel) {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func update() async {
|
private func update() async {
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ActionButton<Label>: View where Label: View {
|
struct ActionButton<Label>: View where Label: View {
|
||||||
|
@State public var showLoader: Bool
|
||||||
@State private var isDuringAction = false
|
@State private var isDuringAction = false
|
||||||
|
|
||||||
private let action: () async -> Void
|
private let action: () async -> Void
|
||||||
private let label: () -> Label
|
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.action = action
|
||||||
self.label = label
|
self.label = label
|
||||||
|
self.showLoader = showLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -32,14 +34,23 @@ struct ActionButton<Label>: View where Label: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
if isDuringAction {
|
if self.showLoader {
|
||||||
LoadingIndicator(isVisible: .constant(true))
|
withLoader()
|
||||||
.transition(.opacity)
|
|
||||||
} else {
|
} else {
|
||||||
label()
|
label()
|
||||||
.transition(.opacity)
|
|
||||||
}
|
}
|
||||||
}.disabled(isDuringAction)
|
}.disabled(isDuringAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func withLoader() -> some View {
|
||||||
|
if isDuringAction {
|
||||||
|
LoadingIndicator(isVisible: .constant(true))
|
||||||
|
.transition(.opacity)
|
||||||
|
} else {
|
||||||
|
label()
|
||||||
|
.transition(.opacity)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,12 @@ struct ImageUploadView: View {
|
||||||
@ObservedObject public var photoAttachment: PhotoAttachment
|
@ObservedObject public var photoAttachment: PhotoAttachment
|
||||||
|
|
||||||
private let delete: () -> Void
|
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.photoAttachment = photoAttachment
|
||||||
self.delete = delete
|
self.delete = delete
|
||||||
|
self.open = open
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -51,7 +53,9 @@ struct ImageUploadView: View {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Menu {
|
Menu {
|
||||||
NavigationLink(value: RouteurDestinations.photoEditor(photoAttachment: photoAttachment)) {
|
Button {
|
||||||
|
self.open()
|
||||||
|
} label: {
|
||||||
Label("Edit", systemImage: "pencil")
|
Label("Edit", systemImage: "pencil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue