Skip to content
Snippets Groups Projects
Commit 07363316 authored by Aylin's avatar Aylin
Browse files

Experimenting with the composition of file preview

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