Skip to content

Commit 181e4b4

Browse files
Added modifier for the message views
1 parent ced3f6e commit 181e4b4

File tree

10 files changed

+33
-1
lines changed

10 files changed

+33
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public struct FileAttachmentsContainer<Factory: ViewFactory>: View {
5454
}
5555
.padding(.all, 4)
5656
}
57+
.modifier(factory.makeMessageViewModifier())
5758
.messageBubble(for: message, isFirst: isFirst)
5859
}
5960
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/ImageAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
5757
}
5858
}
5959
}
60+
.modifier(factory.makeMessageViewModifier())
6061
.messageBubble(for: message, isFirst: isFirst)
6162
.fullScreenCover(isPresented: $galleryShown, onDismiss: {
6263
self.selectedIndex = 0

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
5353
}
5454
}
5555
.padding(.bottom, 8)
56+
.modifier(factory.makeMessageViewModifier())
5657
.messageBubble(
5758
for: message,
5859
isFirst: isFirst,

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public struct MessageTextView<Factory: ViewFactory>: View {
128128
.foregroundColor(textColor(for: message))
129129
.font(fonts.body)
130130
}
131+
.modifier(factory.makeMessageViewModifier())
131132
.messageBubble(for: message, isFirst: isFirst)
132133
}
133134
}
@@ -155,6 +156,7 @@ public struct EmojiTextView<Factory: ViewFactory>: View {
155156
Text(message.text)
156157
.font(fonts.emoji)
157158
}
159+
.modifier(factory.makeMessageViewModifier())
158160
.messageBubble(for: message, isFirst: isFirst)
159161
} else {
160162
Text(message.text)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/QuotedMessageView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
2929
)
3030

3131
QuotedMessageView(
32+
factory: factory,
3233
quotedMessage: quotedMessage,
3334
fillAvailableSpace: fillAvailableSpace,
3435
forceLeftToRight: forceLeftToRight
3536
)
3637
} else {
3738
QuotedMessageView(
39+
factory: factory,
3840
quotedMessage: quotedMessage,
3941
fillAvailableSpace: fillAvailableSpace,
4042
forceLeftToRight: forceLeftToRight
@@ -54,23 +56,26 @@ struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
5456
}
5557

5658
/// View for the quoted message.
57-
public struct QuotedMessageView: View {
59+
public struct QuotedMessageView<Factory: ViewFactory>: View {
5860

5961
@Injected(\.images) private var images
6062
@Injected(\.fonts) private var fonts
6163
@Injected(\.colors) private var colors
6264

6365
private let attachmentWidth: CGFloat = 36
6466

67+
public var factory: Factory
6568
public var quotedMessage: ChatMessage
6669
public var fillAvailableSpace: Bool
6770
public var forceLeftToRight: Bool
6871

6972
public init(
73+
factory: Factory,
7074
quotedMessage: ChatMessage,
7175
fillAvailableSpace: Bool,
7276
forceLeftToRight: Bool
7377
) {
78+
self.factory = factory
7479
self.quotedMessage = quotedMessage
7580
self.fillAvailableSpace = fillAvailableSpace
7681
self.forceLeftToRight = forceLeftToRight
@@ -126,6 +131,7 @@ public struct QuotedMessageView: View {
126131
}
127132
.id(quotedMessage.messageId)
128133
.padding(.all, 8)
134+
.modifier(factory.makeMessageViewModifier())
129135
.messageBubble(
130136
for: quotedMessage,
131137
isFirst: true,

Sources/StreamChatSwiftUI/ChatChannel/MessageList/VideoAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public struct VideoAttachmentsContainer<Factory: ViewFactory>: View {
3131
width: width
3232
)
3333
}
34+
.modifier(factory.makeMessageViewModifier())
3435
.messageBubble(for: message, isFirst: false)
3536
} else {
3637
VideoAttachmentsList(

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ extension ViewFactory {
204204
EmptyViewModifier()
205205
}
206206

207+
public func makeMessageViewModifier() -> some ViewModifier {
208+
EmptyViewModifier()
209+
}
210+
207211
public func makeMessageAvatarView(for userDisplayInfo: UserDisplayInfo) -> some View {
208212
MessageAvatarView(avatarURL: userDisplayInfo.imageURL)
209213
}

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public protocol ViewFactory: AnyObject {
186186
/// Returns a view modifier applied to the message list.
187187
func makeMessageListModifier() -> MessageListModifier
188188

189+
associatedtype MessageViewModifier: ViewModifier
190+
/// Returns a view modifier applied to the message view.
191+
func makeMessageViewModifier() -> MessageViewModifier
192+
189193
associatedtype UserAvatar: View
190194
/// Creates the message avatar view.
191195
/// - Parameter userDisplayInfo: the author's display info.

StreamChatSwiftUITests/Tests/ChatChannel/QuotedMessageView_Tests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class QuotedMessageView_Tests: StreamChatTestCase {
3434
func test_quotedMessageView_snapshot() {
3535
// Given
3636
let view = QuotedMessageView(
37+
factory: DefaultViewFactory.shared,
3738
quotedMessage: testMessage,
3839
fillAvailableSpace: true,
3940
forceLeftToRight: true

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,17 @@ class ViewFactory_Tests: StreamChatTestCase {
618618
// Then
619619
XCTAssert(modifier is EmptyViewModifier)
620620
}
621+
622+
func test_viewFactory_makeMessageViewModifier() {
623+
// Given
624+
let viewFactory = DefaultViewFactory.shared
625+
626+
// When
627+
let modifier = viewFactory.makeMessageViewModifier()
628+
629+
// Then
630+
XCTAssert(modifier is EmptyViewModifier)
631+
}
621632
}
622633

623634
extension ChannelAction: Equatable {

0 commit comments

Comments
 (0)