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

Making the code of Buttons (open, share, delete, download) more readable

parent 3b849b0b
No related branches found
No related tags found
1 merge request!79Resolve "Add comments to: AttachmentViewMain.swift"
......@@ -132,46 +132,18 @@ struct AttPrev:View{
Group{
CardV(title: self.attachment.myName,
//those are the actions visable under the cklicked preview
//those are the actions visable under the clicked preview
actions: self.isDownloaded||self.shouldBeDownloaded ?
[
/*
self.ActionView(NSLocalizedString("delete", comment: ""),
icon: AnyView(Image(systemName: "trash")),
onClick: {
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.name!)
do {
try FileManager.default.removeItem(at: filename)
} catch let error as NSError {
print("Error: \(error)")
}
self.isDownloaded = false
}
), */
self.ActionView(NSLocalizedString("open", comment: ""),
icon: AnyView(Image(systemName: "arrow.up.and.down").rotationEffect(.degrees(45))),
onClick: {self.isFullScreen.toggle()}
),
AnyView(VStack{
shareButton
Text(NSLocalizedString("share", comment: "")).font(.system(size: 12)).foregroundColor(.blue)
})
// anyViewDeleteButton
anyViewOpenButton,
anyViewShareButton
]
:
[
self.ActionView(NSLocalizedString("download", comment: ""),
icon: AnyView(Image(systemName: "arrow.down.circle")),
onClick: {
self.download()
}
),
//odd but both lists need same length
anyViewDownloadButton,
// both lists need same length
// to make appearance the same
AnyView(EmptyView()),
AnyView(EmptyView())
]
......@@ -181,6 +153,8 @@ struct AttPrev:View{
}
}
// preview resemble the look of A4 format
.aspectRatio(100/141, contentMode: .fit)
.frame(width: UIScreen.main.bounds.width*2/3)//, maxHeight: 500)
//an invisable NavigationLink to open the preview in fullscreen
......@@ -218,13 +192,96 @@ struct AttPrev:View{
}
}
//each of those buttons under the card
func ActionView( _ text:String,icon: AnyView, onClick:@escaping ()->Void={})-> AnyView{
return AnyView(Button(
action: onClick
){VStack{
icon
Text(text).font(.system(size: 12))
}})
// an open button converted into an AnyView
// should open the view fullscreen
var anyViewOpenButton: AnyView {
AnyView(
Button (
action: {
self.isFullScreen.toggle()
},
label: {
VStack {
Image(systemName: "arrow.up.and.down")
.rotationEffect(.degrees(45))
Text("open").font(.system(size: 12))
}
}
)
)
}
// a share button converted into an AnyView
var anyViewShareButton: AnyView {
AnyView(
Button (
action: {
// TODO
//popover the standard apple sharing stuff
/* if let coord = AppDelegate.getAppDelegate().readViewCoordinator {
coord.shareData(self.attachment.myData as NSData)
}*/
},
label: {
VStack {
Image(systemName: "square.and.arrow.up")
Text("share").font(.system(size: 12))
}
}
)
)
}
// a delete button converted into an AnyView
var anyViewDeleteButton: AnyView {
AnyView(
Button (
action: {
// TODO
/*
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
do {
try FileManager.default.removeItem(at: filename)
} catch let error as NSError {
print("Error: \(error)")
}
self.isDownloaded = false
*/
},
label: {
VStack {
Image(systemName: "trash")
Text("delete")
.font(.system(size: 12))
}
}
)
)
}
// a download button converted into an AnyView
// dowloads the file into the documents directory
var anyViewDownloadButton: AnyView {
AnyView(
Button (
action: {
self.download()
},
label: {
VStack {
Image(systemName: "arrow.down.circle")
Text("download")
.font(.system(size: 12))
}
}
)
)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment