Skip to content

Commit 10881e2

Browse files
Updated rendering of attachments with text
1 parent d151f59 commit 10881e2

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/ImageAttachmentView.swift

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,7 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
4949
}
5050

5151
if !message.text.isEmpty {
52-
HStack {
53-
Text(message.text)
54-
.standardPadding()
55-
.foregroundColor(textColor(for: message))
56-
Spacer()
57-
}
58-
.background(Color(backgroundColor))
52+
AttachmentTextView(message: message)
5953
}
6054
}
6155
}
@@ -77,16 +71,34 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
7771
)
7872
}
7973
}
74+
}
75+
76+
struct AttachmentTextView: View {
77+
78+
@Injected(\.colors) private var colors
79+
80+
var message: ChatMessage
81+
82+
var body: some View {
83+
HStack {
84+
Text(message.text)
85+
.standardPadding()
86+
.foregroundColor(textColor(for: message))
87+
Spacer()
88+
}
89+
.background(Color(backgroundColor))
90+
}
8091

8192
private var backgroundColor: UIColor {
93+
var colors = colors
8294
if message.isSentByCurrentUser {
8395
if message.type == .ephemeral {
8496
return colors.background8
8597
} else {
86-
return colors.background6
98+
return colors.messageCurrentUserBackground[0]
8799
}
88100
} else {
89-
return colors.background8
101+
return colors.messageOtherUserBackground[0]
90102
}
91103
}
92104
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/VideoAttachmentView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct VideoAttachmentsContainer<Factory: ViewFactory>: View {
1616
@Binding var scrolledId: String?
1717

1818
public var body: some View {
19-
VStack {
19+
VStack(spacing: 0) {
2020
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
2121
VStack {
2222
factory.makeQuotedMessageView(
@@ -45,7 +45,14 @@ public struct VideoAttachmentsContainer<Factory: ViewFactory>: View {
4545
width: width
4646
)
4747
}
48+
49+
if !message.text.isEmpty {
50+
AttachmentTextView(message: message)
51+
}
4852
}
53+
.if(!message.text.isEmpty, transform: { view in
54+
view.messageBubble(for: message, isFirst: true, cornerRadius: 24)
55+
})
4956
}
5057
}
5158

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelTestHelpers.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ class ChatChannelTestHelpers {
114114
return giphyAttachments
115115
}()
116116

117+
static var videoAttachment: ChatMessageVideoAttachment = {
118+
let attachmentFile = AttachmentFile(type: .mp4, size: 0, mimeType: "video/mp4")
119+
let uploadingState = AttachmentUploadingState(
120+
localFileURL: testURL,
121+
state: .pendingUpload,
122+
file: attachmentFile
123+
)
124+
125+
return ChatMessageVideoAttachment(
126+
id: .unique,
127+
type: .video,
128+
payload: VideoAttachmentPayload(
129+
title: "test",
130+
videoRemoteURL: testURL,
131+
file: attachmentFile,
132+
extraData: nil
133+
),
134+
uploadingState: uploadingState
135+
)
136+
137+
}()
138+
117139
static var linkAttachments: [AnyChatMessageAttachment] = {
118140
let attachmentFile = AttachmentFile(type: .generic, size: 0, mimeType: "video/mp4")
119141
let uploadingState = AttachmentUploadingState(

StreamChatSwiftUITests/Tests/ChatChannel/MessageContainerView_Tests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,52 @@ class MessageContainerView_Tests: StreamChatTestCase {
6060
testMessageViewContainerSnapshot(message: message)
6161
}
6262

63+
func test_videoAttachment_snapshotNoText() {
64+
// Given
65+
let attachment = ChatChannelTestHelpers.videoAttachment
66+
let message = ChatMessage.mock(
67+
id: .unique,
68+
cid: .unique,
69+
text: "",
70+
author: .mock(id: .unique)
71+
)
72+
73+
// When
74+
let view = VideoAttachmentView(
75+
attachment: attachment,
76+
message: message,
77+
width: 2 * defaultScreenSize.width / 3
78+
)
79+
.applyDefaultSize()
80+
81+
// Then
82+
assertSnapshot(matching: view, as: .image)
83+
}
84+
85+
func test_videoAttachment_snapshotText() {
86+
// Given
87+
let message = ChatMessage.mock(
88+
id: .unique,
89+
cid: .unique,
90+
text: "Test message",
91+
author: .mock(id: .unique),
92+
attachments: ChatChannelTestHelpers.videoAttachments
93+
)
94+
95+
// When
96+
let view = VideoAttachmentsContainer(
97+
factory: DefaultViewFactory.shared,
98+
message: message,
99+
width: 2 * defaultScreenSize.width / 3,
100+
scrolledId: .constant(nil)
101+
)
102+
.frame(width: 200)
103+
.padding()
104+
105+
// Then
106+
assertSnapshot(matching: view, as: .image)
107+
}
108+
63109
// MARK: - private
64110

65111
func testMessageViewContainerSnapshot(message: ChatMessage) {
Loading
Loading

0 commit comments

Comments
 (0)