Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
mobile
iOS
Elixxir dApps SDK Swift
Commits
41cc0515
Commit
41cc0515
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Implement file transfers UI in ChatView
parent
0758b846
No related branches found
No related tags found
2 merge requests
!124
File transfers example
,
!102
Release 1.0.0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Examples/xx-messenger/Sources/ChatFeature/ChatFeature.swift
+4
-1
4 additions, 1 deletion
Examples/xx-messenger/Sources/ChatFeature/ChatFeature.swift
Examples/xx-messenger/Sources/ChatFeature/ChatView.swift
+75
-12
75 additions, 12 deletions
Examples/xx-messenger/Sources/ChatFeature/ChatView.swift
with
79 additions
and
13 deletions
Examples/xx-messenger/Sources/ChatFeature/ChatFeature.swift
+
4
−
1
View file @
41cc0515
...
@@ -18,13 +18,15 @@ public struct ChatState: Equatable, Identifiable {
...
@@ -18,13 +18,15 @@ public struct ChatState: Equatable, Identifiable {
date
:
Date
,
date
:
Date
,
senderId
:
Data
,
senderId
:
Data
,
text
:
String
,
text
:
String
,
status
:
XXModels
.
Message
.
Status
status
:
XXModels
.
Message
.
Status
,
fileTransfer
:
XXModels
.
FileTransfer
?
=
nil
)
{
)
{
self
.
id
=
id
self
.
id
=
id
self
.
date
=
date
self
.
date
=
date
self
.
senderId
=
senderId
self
.
senderId
=
senderId
self
.
text
=
text
self
.
text
=
text
self
.
status
=
status
self
.
status
=
status
self
.
fileTransfer
=
fileTransfer
}
}
public
var
id
:
Int64
public
var
id
:
Int64
...
@@ -32,6 +34,7 @@ public struct ChatState: Equatable, Identifiable {
...
@@ -32,6 +34,7 @@ public struct ChatState: Equatable, Identifiable {
public
var
senderId
:
Data
public
var
senderId
:
Data
public
var
text
:
String
public
var
text
:
String
public
var
status
:
XXModels
.
Message
.
Status
public
var
status
:
XXModels
.
Message
.
Status
public
var
fileTransfer
:
XXModels
.
FileTransfer
?
}
}
public
init
(
public
init
(
...
...
This diff is collapsed.
Click to expand it.
Examples/xx-messenger/Sources/ChatFeature/ChatView.swift
+
75
−
12
View file @
41cc0515
...
@@ -112,6 +112,10 @@ public struct ChatView: View {
...
@@ -112,6 +112,10 @@ public struct ChatView: View {
message
.
senderId
==
myContactId
?
.
trailing
:
.
leading
message
.
senderId
==
myContactId
?
.
trailing
:
.
leading
}
}
var
paddingEdge
:
Edge
.
Set
{
message
.
senderId
==
myContactId
?
.
leading
:
.
trailing
}
var
textColor
:
Color
?
{
var
textColor
:
Color
?
{
message
.
senderId
==
myContactId
?
Color
.
white
:
nil
message
.
senderId
==
myContactId
?
Color
.
white
:
nil
}
}
...
@@ -123,20 +127,38 @@ public struct ChatView: View {
...
@@ -123,20 +127,38 @@ public struct ChatView: View {
.
font
(
.
footnote
)
.
font
(
.
footnote
)
.
frame
(
maxWidth
:
.
infinity
,
alignment
:
alignment
)
.
frame
(
maxWidth
:
.
infinity
,
alignment
:
alignment
)
Text
(
message
.
text
)
VStack
(
alignment
:
.
leading
)
{
.
foregroundColor
(
textColor
)
if
let
fileTransfer
=
message
.
fileTransfer
{
.
padding
(
.
horizontal
,
16
)
Text
(
"
\(
fileTransfer
.
name
)
(
\(
fileTransfer
.
type
)
)"
)
.
padding
(
.
vertical
,
8
)
if
fileTransfer
.
progress
<
1
{
.
background
{
ProgressView
(
value
:
fileTransfer
.
progress
)
if
message
.
senderId
==
myContactId
{
}
RoundedRectangle
(
cornerRadius
:
16
,
style
:
.
continuous
)
if
fileTransfer
.
type
==
"image"
,
.
fill
(
Color
.
blue
)
let
data
=
fileTransfer
.
data
,
}
else
{
let
image
=
UIImage
(
data
:
data
)
{
RoundedRectangle
(
cornerRadius
:
16
,
style
:
.
continuous
)
Image
(
uiImage
:
image
)
.
fill
(
Material
.
ultraThick
)
.
resizable
()
.
scaledToFit
()
.
padding
(
.
bottom
,
8
)
}
}
}
else
{
Text
(
message
.
text
)
}
}
.
frame
(
maxWidth
:
.
infinity
,
alignment
:
alignment
)
}
.
foregroundColor
(
textColor
)
.
padding
(
.
horizontal
,
16
)
.
padding
(
.
vertical
,
8
)
.
background
{
if
message
.
senderId
==
myContactId
{
RoundedRectangle
(
cornerRadius
:
16
,
style
:
.
continuous
)
.
fill
(
Color
.
blue
)
}
else
{
RoundedRectangle
(
cornerRadius
:
16
,
style
:
.
continuous
)
.
fill
(
Material
.
ultraThick
)
}
}
.
frame
(
maxWidth
:
.
infinity
,
alignment
:
alignment
)
.
padding
(
paddingEdge
,
60
)
}
}
.
padding
(
.
horizontal
)
.
padding
(
.
horizontal
)
}
}
...
@@ -178,6 +200,47 @@ public struct ChatView_Previews: PreviewProvider {
...
@@ -178,6 +200,47 @@ public struct ChatView_Previews: PreviewProvider {
text
:
"Hi!"
,
text
:
"Hi!"
,
status
:
.
sent
status
:
.
sent
),
),
.
init
(
id
:
3
,
date
:
Date
(),
senderId
:
"contact-id"
.
data
(
using
:
.
utf8
)
!
,
text
:
""
,
status
:
.
received
,
fileTransfer
:
.
init
(
id
:
Data
(),
contactId
:
Data
(),
name
:
"received_file.jpeg"
,
type
:
"image"
,
progress
:
0.75
,
isIncoming
:
true
)
),
.
init
(
id
:
4
,
date
:
Date
(),
senderId
:
"my-contact-id"
.
data
(
using
:
.
utf8
)
!
,
text
:
""
,
status
:
.
sent
,
fileTransfer
:
.
init
(
id
:
Data
(),
contactId
:
Data
(),
name
:
"sent_file.jpeg"
,
type
:
"image"
,
data
:
{
let
bounds
=
CGRect
(
origin
:
.
zero
,
size
:
.
init
(
width
:
4
,
height
:
3
))
let
format
=
UIGraphicsImageRendererFormat
()
format
.
scale
=
1
let
renderer
=
UIGraphicsImageRenderer
(
bounds
:
bounds
,
format
:
format
)
let
image
=
renderer
.
image
{
ctx
in
UIColor
.
systemMint
.
setFill
()
ctx
.
fill
(
bounds
)
}
return
image
.
jpegData
(
compressionQuality
:
0.72
)
}(),
progress
:
1
,
isIncoming
:
true
)
),
],
],
failure
:
"Something went wrong when fetching messages from database."
,
failure
:
"Something went wrong when fetching messages from database."
,
sendFailure
:
"Something went wrong when sending message."
sendFailure
:
"Something went wrong when sending message."
...
...
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