Skip to content
Snippets Groups Projects
Commit 6b05eec3 authored by cruxfilm's avatar cruxfilm
Browse files

Disabled interaction with PDF/txt preview, minor layout changes and code simplifications.

parent 81481ea8
Branches
No related tags found
1 merge request!83Resolve "Integrate attachment functionality in new ComposeView"
......@@ -46,8 +46,7 @@ struct AddAttachmentsView: View {
if sheetState == .imageImport {
// open the Gallery and let user pick an image
ImagePicker(image: self.$inputImage)
}
else if sheetState == .fullScreenFilePreview {
} else if sheetState == .fullScreenFilePreview {
// open the attachment in 'fullScreenAttachment' fullscreen
if let attachment = fullScreenAttachment {
// file name
......@@ -57,8 +56,7 @@ struct AddAttachmentsView: View {
QuickLookView(name: attachment.myName, data: attachment.myData, shallDL: false)
.aspectRatio(100/141, contentMode: .fit)
}
}
else {
} else {
// this should be shown because the sheetState .none is
// a default
EmptyView()
......@@ -77,15 +75,13 @@ struct AddAttachmentsView: View {
image = Image(uiImage: inputImage)
self.sheetState = .none
}
}
else if sheetState == .fullScreenFilePreview {
} else if sheetState == .fullScreenFilePreview {
return {
self.showSheet = false
self.sheetState = .none
self.fullScreenAttachment = nil
}
}
else {
} else {
return {}// nothing
}
}
......@@ -107,117 +103,104 @@ struct AddAttachmentsView: View {
filePreviews
}
.padding(4)
// using .sheet with multiple sheet views accoring to sheetStates
.sheet(isPresented: $showSheet, onDismiss: sheetOnDismiss()) {
sheetContent()
}
.padding(4)
// using .sheet with multiple sheet views accoring to sheetStates
.sheet(isPresented: $showSheet, onDismiss: sheetOnDismiss()) {
sheetContent()
}
}
}
/// a view that contains the upload button for files
var fileUploadButton: some View {
Button {
importNewFile.toggle()
} label: {
ZStack(alignment: Alignment(horizontal: .trailing, vertical: .top)) {
Image(systemName: "doc.badge.plus")
.font(.system(size: 50))
}
Button {
importNewFile.toggle()
} label: {
Image(systemName: "doc.badge.plus").font(.system(size: 50))
}
// file import when button is pressed
.fileImporter(isPresented: $importNewFile, allowedContentTypes: [.plainText,.image,.pdf]) {
(res) in
do {
// get fileURL of selected file
let fileURL = try res.get()
// get fileName from URL of that file
let fileName = fileURL.lastPathComponent
// get file data
let fileData = try Data(contentsOf: fileURL)
// create Attachment and add in to the attachments list
let newAttachment = Attachment(fileName: fileName, fileData: fileData)
model.attachments.append(newAttachment)
} catch {
// Error while loading file
print("Error while importing file.")
}
// file import when button is pressed
.fileImporter(isPresented: $importNewFile, allowedContentTypes: [.plainText,.image,.pdf]) {
(res) in
do {
// get fileURL of selected file
let fileURL = try res.get()
// get fileName from URL of that file
let fileName = fileURL.lastPathComponent
// get file data
let fileData = try Data(contentsOf: fileURL)
// create Attachment and add in to the attachments list
let newAttachment = Attachment(fileName: fileName, fileData: fileData)
model.attachments.append(newAttachment)
}
catch {
// Error while loading file
print("Error while importing file.")
}
} // end of fileImport
} // end of fileImport
}
/// a view that contains the upload button for pictures
var imageUploadButton: some View {
Button {
self.sheetState = .imageImport
showSheet.toggle()
} label: {
// try to imitate SF Symbol "doc.badge.plus"
// with "photo"
ZStack(alignment: Alignment(horizontal: .leading, vertical: .bottom)) {
Image(systemName: "photo")
.font(.system(size: 50))
Image(systemName: "plus")
.font(Font.system(size: 19, weight: .bold))
.foregroundColor(Color(.systemBackground))
.padding(3)
.background(Circle().fill(Color.accentColor))
.padding(3)
.background(Circle().fill(Color(.systemBackground)))
.offset(x: -8, y: 8)
}
Button {
self.sheetState = .imageImport
showSheet.toggle()
} label: {
// try to imitate SF Symbol "doc.badge.plus"
// with "photo"
ZStack(alignment: .bottomLeading) {
Image(systemName: "photo")
.font(.system(size: 50))
Image(systemName: "plus")
.font(Font.system(size: 19, weight: .bold))
.foregroundColor(Color(.systemBackground))
.padding(3)
.background(Circle().fill(Color.accentColor))
.padding(3)
.background(Circle().fill(Color(.systemBackground)))
.offset(x: -8, y: 8)
}
}
}
/// 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: .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))
ForEach(model.attachments, id: \.self.myID) { currentFile in
ZStack {
// file preview using quicklook
QuickLookView(name: currentFile.myName, data: currentFile.myData, shallDL: false)
.padding(3)
.background(RoundedRectangle(cornerRadius: 5)
.stroke(Color.secondary, lineWidth: 2))
.allowsHitTesting(false)
VStack(alignment: .trailing) {
// delete button in upper right corner
Button {
if let deleteIndex = model.attachments.firstIndex(of: currentFile) {
model.attachments.remove(at: deleteIndex)
}
Spacer()
// print file name and size
Text(currentFile.myName + ", " + currentFile.countData())
.lineLimit(1)
.frame(width: 90)
.font(.caption)
.foregroundColor(.secondary)
.truncationMode(.middle)
.padding(2)
.background(Color(.systemBackground).opacity(1))
.clipShape(RoundedRectangle(cornerRadius: 5))
} label: {
Image(systemName: "xmark").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
})
.padding(5)
Spacer()
// display file name and size
Text(currentFile.myName + ", " + currentFile.countData())
.lineLimit(1)
.font(.caption)
.foregroundColor(.secondary)
.truncationMode(.middle)
.frame(maxWidth: .infinity)
.padding(3)
.background(RoundedRectangle(cornerRadius: 5)
.fill(Color(.systemBackground)).opacity(0.8))
}
.frame(maxWidth: .infinity)
}
.frame(width: 100, height: 141)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment