Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
enzevalos_iphone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
enzevalos
enzevalos_iphone
Commits
d450a437
Commit
d450a437
authored
4 years ago
by
Aylin
Browse files
Options
Downloads
Patches
Plain Diff
Making the code of Buttons (open, share, delete, download) more readable
parent
3b849b0b
No related branches found
No related tags found
1 merge request
!79
Resolve "Add comments to: AttachmentViewMain.swift"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
+100
-43
100 additions, 43 deletions
...phone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
with
100 additions
and
43 deletions
enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift
+
100
−
43
View file @
d450a437
...
...
@@ -132,46 +132,18 @@ struct AttPrev:View{
Group
{
CardV
(
title
:
self
.
attachment
.
myName
,
//those are the actions visable under the c
k
licked 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
))
}
}
)
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment