Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix voice recording view layout and colors #689

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Improve message search performance [#680](https://github.com/GetStream/stream-chat-swiftui/pull/680)
### ✅ Added
- Make `CreatePollView` public [#685](https://github.com/GetStream/stream-chat-swiftui/pull/685)
### 🔄 Changed
- 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/)

# [4.68.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.68.0)
_December 03, 2024_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,37 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {

public var body: some View {
VStack {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
isInComposer: false,
scrolledId: $scrolledId
)
}

ForEach(message.voiceRecordingAttachments, id: \.self) { attachment in
VoiceRecordingView(
handler: handler,
addedVoiceRecording: AddedVoiceRecording(
url: attachment.payload.voiceRecordingURL,
duration: attachment.payload.duration ?? 0,
waveform: attachment.payload.waveformData ?? []
),
index: index(for: attachment)
)
VStack {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
isInComposer: false,
scrolledId: $scrolledId
)
}

ForEach(message.voiceRecordingAttachments, id: \.self) { attachment in
VoiceRecordingView(
handler: handler,
addedVoiceRecording: AddedVoiceRecording(
url: attachment.payload.voiceRecordingURL,
duration: attachment.payload.duration ?? 0,
waveform: attachment.payload.waveformData ?? []
),
index: index(for: attachment)
)
}
}
.padding(.all, 8)
.background(Color(colors.background8))
.cornerRadius(16)
if !message.text.isEmpty {
AttachmentTextView(message: message)
.frame(maxWidth: .infinity)
.cornerRadius(16)
}
}
.padding(.all, 2)
nuno-vieira marked this conversation as resolved.
Show resolved Hide resolved
.onReceive(handler.$context, perform: { value in
guard message.voiceRecordingAttachments.count > 1 else { return }
if value.state == .playing {
Expand All @@ -87,10 +92,6 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {
.onAppear {
player.subscribe(handler)
}
.padding(.all, 8)
.background(Color(colors.background))
.cornerRadius(16)
.padding(.all, 4)
.modifier(
factory.makeMessageViewModifier(
for: MessageModifierInfo(message: message, isFirst: isFirst)
Expand Down
101 changes: 98 additions & 3 deletions StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,15 @@
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_messageViewVoiceRecording_snapshot() {
func test_messageViewVoiceRecordingFromParticipant_snapshot() {
// Given
let voiceMessage = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "",
author: .mock(id: .unique),
attachments: ChatChannelTestHelpers.voiceRecordingAttachments
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
isSentByCurrentUser: false
)

// When
Expand All @@ -315,7 +316,101 @@
.padding()

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
AssertSnapshot(
view,
variants: .onlyUserInterfaceStyles,
size: CGSize(width: defaultScreenSize.width, height: 130)
)
}

func test_messageViewVoiceRecordingFromMe_snapshot() {
// Given
let voiceMessage = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "",
author: .mock(id: .unique),
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
isSentByCurrentUser: true
)

// When
let view = MessageView(
factory: DefaultViewFactory.shared,
message: voiceMessage,
contentWidth: defaultScreenSize.width,
isFirst: true,
scrolledId: .constant(nil)
)
.frame(width: defaultScreenSize.width, height: 130)
.padding()

// Then
AssertSnapshot(
view,
variants: .onlyUserInterfaceStyles,
size: CGSize(width: defaultScreenSize.width, height: 130)
)
}

func test_messageViewVoiceRecordingWithTextFromParticipant_snapshot() {
// Given
let voiceMessage = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "Hello",
author: .mock(id: .unique),
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
isSentByCurrentUser: false
)

// When
let view = MessageView(
factory: DefaultViewFactory.shared,
message: voiceMessage,
contentWidth: defaultScreenSize.width,
isFirst: true,
scrolledId: .constant(nil)
)
.frame(width: defaultScreenSize.width, height: 130)
.padding()

// Then
AssertSnapshot(

Check failure on line 379 in StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageViewVoiceRecordingWithTextFromParticipant_snapshot, failed - Snapshot "default.dark" does not match reference.

Check failure on line 379 in StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageViewVoiceRecordingWithTextFromParticipant_snapshot, failed - Snapshot "default.dark" does not match reference.
view,
variants: .onlyUserInterfaceStyles,
size: CGSize(width: defaultScreenSize.width, height: 130)
)
}

func test_messageViewVoiceRecordingWithTextFromMe_snapshot() {
// Given
let voiceMessage = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "Hello",
author: .mock(id: .unique),
attachments: ChatChannelTestHelpers.voiceRecordingAttachments,
isSentByCurrentUser: true
)

// When
let view = MessageView(
factory: DefaultViewFactory.shared,
message: voiceMessage,
contentWidth: defaultScreenSize.width,
isFirst: true,
scrolledId: .constant(nil)
)
.frame(width: defaultScreenSize.width, height: 130)
.padding()

// Then
AssertSnapshot(

Check failure on line 409 in StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageViewVoiceRecordingWithTextFromMe_snapshot, failed - Snapshot "default.dark" does not match reference.

Check failure on line 409 in StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageViewVoiceRecordingWithTextFromMe_snapshot, failed - Snapshot "default.dark" does not match reference.
view,
variants: .onlyUserInterfaceStyles,
size: CGSize(width: defaultScreenSize.width, height: 130)
)
}

func test_messageViewFileText_snapshot() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading