Skip to content

Commit a58e648

Browse files
authored
Fix voice recording view layout and colors (#689)
1 parent 9adc3cf commit a58e648

12 files changed

+125
-27
lines changed

β€ŽCHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
- Improve message search performance [#680](https://github.com/GetStream/stream-chat-swiftui/pull/680)
1010
### βœ… Added
1111
- Make `CreatePollView` public [#685](https://github.com/GetStream/stream-chat-swiftui/pull/685)
12+
### πŸ”„ Changed
13+
- Update `VoiceRecordingContainerView` background colors and layout by moving the message text outside of the recording cell [#689](https://github.com/GetStream/stream-chat-swiftui/pull/689/)
1214

1315
# [4.68.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.68.0)
1416
_December 03, 2024_

β€ŽSources/StreamChatSwiftUI/ChatChannel/MessageList/AsyncVoiceMessages/VoiceRecordingContainerView.swift

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,37 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {
4040

4141
public var body: some View {
4242
VStack {
43-
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
44-
factory.makeQuotedMessageView(
45-
quotedMessage: quotedMessage,
46-
fillAvailableSpace: !message.attachmentCounts.isEmpty,
47-
isInComposer: false,
48-
scrolledId: $scrolledId
49-
)
50-
}
51-
52-
ForEach(message.voiceRecordingAttachments, id: \.self) { attachment in
53-
VoiceRecordingView(
54-
handler: handler,
55-
addedVoiceRecording: AddedVoiceRecording(
56-
url: attachment.payload.voiceRecordingURL,
57-
duration: attachment.payload.duration ?? 0,
58-
waveform: attachment.payload.waveformData ?? []
59-
),
60-
index: index(for: attachment)
61-
)
43+
VStack {
44+
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
45+
factory.makeQuotedMessageView(
46+
quotedMessage: quotedMessage,
47+
fillAvailableSpace: !message.attachmentCounts.isEmpty,
48+
isInComposer: false,
49+
scrolledId: $scrolledId
50+
)
51+
}
52+
53+
ForEach(message.voiceRecordingAttachments, id: \.self) { attachment in
54+
VoiceRecordingView(
55+
handler: handler,
56+
addedVoiceRecording: AddedVoiceRecording(
57+
url: attachment.payload.voiceRecordingURL,
58+
duration: attachment.payload.duration ?? 0,
59+
waveform: attachment.payload.waveformData ?? []
60+
),
61+
index: index(for: attachment)
62+
)
63+
}
6264
}
65+
.padding(.all, 8)
66+
.background(Color(colors.background8))
67+
.cornerRadius(16)
6368
if !message.text.isEmpty {
6469
AttachmentTextView(message: message)
6570
.frame(maxWidth: .infinity)
66-
.cornerRadius(16)
6771
}
6872
}
73+
.padding(.all, 2)
6974
.onReceive(handler.$context, perform: { value in
7075
guard message.voiceRecordingAttachments.count > 1 else { return }
7176
if value.state == .playing {
@@ -87,10 +92,6 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {
8792
.onAppear {
8893
player.subscribe(handler)
8994
}
90-
.padding(.all, 8)
91-
.background(Color(colors.background))
92-
.cornerRadius(16)
93-
.padding(.all, 4)
9495
.modifier(
9596
factory.makeMessageViewModifier(
9697
for: MessageModifierInfo(message: message, isFirst: isFirst)

β€ŽStreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,15 @@ class MessageView_Tests: StreamChatTestCase {
293293
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
294294
}
295295

296-
func test_messageViewVoiceRecording_snapshot() {
296+
func test_messageViewVoiceRecordingFromParticipant_snapshot() {
297297
// Given
298298
let voiceMessage = ChatMessage.mock(
299299
id: .unique,
300300
cid: .unique,
301301
text: "",
302302
author: .mock(id: .unique),
303-
attachments: ChatChannelTestHelpers.voiceRecordingAttachments
303+
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
304+
isSentByCurrentUser: false
304305
)
305306

306307
// When
@@ -315,7 +316,101 @@ class MessageView_Tests: StreamChatTestCase {
315316
.padding()
316317

317318
// Then
318-
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
319+
AssertSnapshot(
320+
view,
321+
variants: .onlyUserInterfaceStyles,
322+
size: CGSize(width: defaultScreenSize.width, height: 130)
323+
)
324+
}
325+
326+
func test_messageViewVoiceRecordingFromMe_snapshot() {
327+
// Given
328+
let voiceMessage = ChatMessage.mock(
329+
id: .unique,
330+
cid: .unique,
331+
text: "",
332+
author: .mock(id: .unique),
333+
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
334+
isSentByCurrentUser: true
335+
)
336+
337+
// When
338+
let view = MessageView(
339+
factory: DefaultViewFactory.shared,
340+
message: voiceMessage,
341+
contentWidth: defaultScreenSize.width,
342+
isFirst: true,
343+
scrolledId: .constant(nil)
344+
)
345+
.frame(width: defaultScreenSize.width, height: 130)
346+
.padding()
347+
348+
// Then
349+
AssertSnapshot(
350+
view,
351+
variants: .onlyUserInterfaceStyles,
352+
size: CGSize(width: defaultScreenSize.width, height: 130)
353+
)
354+
}
355+
356+
func test_messageViewVoiceRecordingWithTextFromParticipant_snapshot() {
357+
// Given
358+
let voiceMessage = ChatMessage.mock(
359+
id: .unique,
360+
cid: .unique,
361+
text: "Hello",
362+
author: .mock(id: .unique),
363+
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
364+
isSentByCurrentUser: false
365+
)
366+
367+
// When
368+
let view = MessageView(
369+
factory: DefaultViewFactory.shared,
370+
message: voiceMessage,
371+
contentWidth: defaultScreenSize.width,
372+
isFirst: true,
373+
scrolledId: .constant(nil)
374+
)
375+
.frame(width: defaultScreenSize.width, height: 130)
376+
.padding()
377+
378+
// Then
379+
AssertSnapshot(
380+
view,
381+
variants: .onlyUserInterfaceStyles,
382+
size: CGSize(width: defaultScreenSize.width, height: 130)
383+
)
384+
}
385+
386+
func test_messageViewVoiceRecordingWithTextFromMe_snapshot() {
387+
// Given
388+
let voiceMessage = ChatMessage.mock(
389+
id: .unique,
390+
cid: .unique,
391+
text: "Hello",
392+
author: .mock(id: .unique),
393+
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
394+
isSentByCurrentUser: true
395+
)
396+
397+
// When
398+
let view = MessageView(
399+
factory: DefaultViewFactory.shared,
400+
message: voiceMessage,
401+
contentWidth: defaultScreenSize.width,
402+
isFirst: true,
403+
scrolledId: .constant(nil)
404+
)
405+
.frame(width: defaultScreenSize.width, height: 130)
406+
.padding()
407+
408+
// Then
409+
AssertSnapshot(
410+
view,
411+
variants: .onlyUserInterfaceStyles,
412+
size: CGSize(width: defaultScreenSize.width, height: 130)
413+
)
319414
}
320415

321416
func test_messageViewFileText_snapshot() {
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
Β (0)