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
6b05eec3
Commit
6b05eec3
authored
4 years ago
by
cruxfilm
Browse files
Options
Downloads
Patches
Plain Diff
Disabled interaction with PDF/txt preview, minor layout changes and code simplifications.
parent
81481ea8
Branches
Branches containing commit
No related tags found
1 merge request
!83
Resolve "Integrate attachment functionality in new ComposeView"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift
+85
-102
85 additions, 102 deletions
enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift
with
85 additions
and
102 deletions
enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift
+
85
−
102
View file @
6b05eec3
...
...
@@ -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
)
}
}
}
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