diff --git a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift index c59f0a0d34e510962331abcc098bc47b196a708b..40d952e1d4b8f3bff37083e1695665537c1d91d5 100644 --- a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift +++ b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift @@ -22,10 +22,10 @@ struct Attachment: DisplayAttachment, Equatable { myID = UUID() } - /// a func that returns the size of an attachment file as a string - func countData(attachment: Attachment) -> String { + /// a func that returns the size of the calling attachment file as a string + func countData() -> String { // size in byte - var sizeOfData = Double(attachment.myData.count) + var sizeOfData = Double(self.myData.count) // smaller than 1KB if sizeOfData < 1000 { diff --git a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift index 527f1badbbc810b12c5aff76e7d9d0d45b9a4aa0..d48abfa547ab1d02f2cbf4cf2e79eaef34ff95b3 100644 --- a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift +++ b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift @@ -42,21 +42,24 @@ struct AddAttachmentsView: View { /// a func that returns the right sheet content according to the sheetState @ViewBuilder private func sheetContent() -> some View { + if sheetState == .imageImport { + // open the Gallery and let user pick an image ImagePicker(image: self.$inputImage) } else if sheetState == .fullScreenFilePreview { + // open the attachment in 'fullScreenAttachment' fullscreen if let attachment = fullScreenAttachment { - QuickLookView(name: attachment.myName, data: attachment.myData, shallDL: false).aspectRatio(100/141, contentMode: .fit) - } - else { - // this should never happen because fullScreenFilePreview - // is only nil in the beginning - EmptyView() + // file name + Text(attachment.myName) + .font(Font.headline.weight(.semibold)) + // file preview + QuickLookView(name: attachment.myName, data: attachment.myData, shallDL: false) + .aspectRatio(100/141, contentMode: .fit) } } else { - // this should never happen because the sheetState .none is + // this should be shown because the sheetState .none is // a default EmptyView() } @@ -72,19 +75,21 @@ struct AddAttachmentsView: View { return } image = Image(uiImage: inputImage) + self.sheetState = .none } } else if sheetState == .fullScreenFilePreview { - return {}// nothing + return { + self.showSheet = false + self.sheetState = .none + self.fullScreenAttachment = nil + } } else { return {}// nothing } } - - - /// a view that enables uploading an previewing files and pictures as attachments // TODO: image import and preview are currently not fully supported var body: some View { @@ -103,6 +108,7 @@ struct AddAttachmentsView: View { filePreviews } .padding(4) + // using .sheet with multiple sheet views accoring to sheetStates .sheet(isPresented: $showSheet, onDismiss: sheetOnDismiss()) { sheetContent() } @@ -144,8 +150,8 @@ struct AddAttachmentsView: View { /// a view that contains the upload button for pictures var imageUploadButton: some View { Button { - showSheet.toggle() self.sheetState = .imageImport + showSheet.toggle() } label: { // try to imitate SF Symbol "doc.badge.plus" // with "photo" @@ -168,19 +174,21 @@ struct AddAttachmentsView: View { /// a view that contains several file previews together with their delete buttons var filePreviews: some View { ForEach(model.attachments, id: \.self.myID) { currentFile in - ZStack(alignment: Alignment(horizontal: .trailing, vertical: .top)) { - ZStack(alignment: Alignment(horizontal: .trailing, vertical: .bottom)) { - // file preview using quicklook - QuickLookView(name: currentFile.myName, data: currentFile.myData, shallDL: false) - // resembles A4 format - .frame(width: 100, height: 141) - // creating a custom frame - .clipShape(RoundedRectangle(cornerRadius: 5)) - .padding(0.5) - .background(RoundedRectangle(cornerRadius: 5).fill(Color.gray)) - + ZStack(alignment: .topTrailing) { + VStack { + // delete button in upper right corner + Button { + // remove from attachments list + if let deleteIndex = model.attachments.firstIndex(of: currentFile) { + model.attachments.remove(at: deleteIndex) + } + } label: { + Image(systemName: "multiply") + .font(.system(size: 20)) + } + Spacer() // print file name and size - Text(currentFile.myName + ", " + currentFile.countData(attachment: currentFile)) + Text(currentFile.myName + ", " + currentFile.countData()) .lineLimit(1) .frame(width: 90) .font(.caption) @@ -190,24 +198,24 @@ struct AddAttachmentsView: View { .background(Color(.systemBackground).opacity(1)) .clipShape(RoundedRectangle(cornerRadius: 5)) } - Button { - fullScreenAttachment = currentFile - showSheet.toggle() - self.sheetState = .fullScreenFilePreview - } label: { - Image(systemName: "arrow.up.left.and.arrow.down.right") - } - .offset(x:23, y: 23) - // delete button in upper right corner - Button { - // remove from attachments list - if let deleteIndex = model.attachments.firstIndex(of: currentFile) { - model.attachments.remove(at: deleteIndex) - } - } label: { - Image(systemName: "multiply") - .font(.system(size: 20)) - } + // file preview using quicklook + QuickLookView(name: currentFile.myName, data: currentFile.myData, shallDL: false) + // resembles A4 format + .frame(width: 100, height: 141) + // creating a custom frame + .clipShape(RoundedRectangle(cornerRadius: 5)) + .padding(0.5) + .background(RoundedRectangle(cornerRadius: 5).fill(Color.gray)) + .allowsHitTesting(false) + + // a Rectangle that covers the QuickLookView so that the interactions are "disabled" + Rectangle().fill(Color.black.opacity(0)) + .frame(width: 100, height: 141) + .gesture(LongPressGesture(minimumDuration: 1).onEnded { _ in + fullScreenAttachment = currentFile + self.sheetState = .fullScreenFilePreview + showSheet = true + }) } } } diff --git a/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift b/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift index a35830804f5328c814181660018d9c6833215b86..27fdbc8b4c811aa51be68cd5431363270e79a932 100644 --- a/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift +++ b/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift @@ -68,9 +68,12 @@ class ComposeModel: ObservableObject { do { if let newMCOAttachment = MCOAttachment.init(data: current.myData, filename: current.myName) { convertedAttachments.append(newMCOAttachment) + print("Converted and attached file") } } } + // TODO: something seems to go wrong with sending the attachments + // has to be fixed in the future return OutgoingMail(toAddresses: recipientsModel.toEMails, ccAddresses: recipientsModel.ccEMails,