Skip to content

Commit ff327d2

Browse files
Enabled customizing of message date view
1 parent b71f723 commit ff327d2

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/DeletedMessageView.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ public struct DeletedMessageView: View {
3030
.foregroundColor(Color(colors.textLowEmphasis))
3131
.messageBubble(for: message, isFirst: isFirst)
3232

33-
HStack {
34-
Spacer()
33+
if message.isSentByCurrentUser {
34+
HStack {
35+
Spacer()
36+
37+
Image(uiImage: images.eye)
38+
.customizable()
39+
.frame(maxWidth: 12)
3540

36-
Image(uiImage: images.eye)
37-
.customizable()
38-
.frame(maxWidth: 12)
39-
40-
Text(L10n.Message.onlyVisibleToYou)
41-
.font(fonts.footnote)
42-
43-
Text(dateFormatter.string(from: message.createdAt))
44-
.font(fonts.footnote)
41+
Text(L10n.Message.onlyVisibleToYou)
42+
.font(fonts.footnote)
43+
44+
Text(dateFormatter.string(from: message.createdAt))
45+
.font(fonts.footnote)
46+
}
47+
.foregroundColor(Color(colors.textLowEmphasis))
4548
}
46-
.foregroundColor(Color(colors.textLowEmphasis))
4749
}
4850
}
4951
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
124124
}
125125
}
126126
.onLongPressGesture(perform: {
127-
handleGestureForMessage(showsMessageActions: true)
127+
if !message.isDeleted {
128+
handleGestureForMessage(showsMessageActions: true)
129+
}
128130
})
129131
.offset(x: self.offsetX)
130132
.simultaneousGesture(
@@ -180,15 +182,15 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
180182
)
181183

182184
if messageListConfig.messageDisplayOptions.showMessageDate {
183-
MessageDateView(message: message)
185+
factory.makeMessageDateView(for: message)
184186
}
185187
}
186188
} else if !message.isSentByCurrentUser
187189
&& !channel.isDirectMessageChannel
188190
&& messageListConfig.messageDisplayOptions.showAuthorName {
189-
MessageAuthorAndDateView(message: message)
191+
factory.makeMessageAuthorAndDateView(for: message)
190192
} else if messageListConfig.messageDisplayOptions.showMessageDate {
191-
MessageDateView(message: message)
193+
factory.makeMessageDateView(for: message)
192194
}
193195
}
194196
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ extension ViewFactory {
289289
)
290290
}
291291

292+
public func makeMessageDateView(for message: ChatMessage) -> some View {
293+
MessageDateView(message: message)
294+
}
295+
296+
public func makeMessageAuthorAndDateView(for message: ChatMessage) -> some View {
297+
MessageAuthorAndDateView(message: message)
298+
}
299+
292300
public func makeImageAttachmentView(
293301
for message: ChatMessage,
294302
isFirst: Bool,

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ public protocol ViewFactory: AnyObject {
277277
scrolledId: Binding<String?>
278278
) -> MessageTextViewType
279279

280+
associatedtype MessageDateViewType: View
281+
/// Creates a view for the date info shown below a message.
282+
/// - Parameter message: the chat message for which the date info is displayed.
283+
/// - Returns: view shown in the date indicator slot.
284+
func makeMessageDateView(for message: ChatMessage) -> MessageDateViewType
285+
286+
associatedtype MessageAuthorAndDateViewType: View
287+
/// Creates a view for the date and author info shown below a message.
288+
/// - Parameter message: the chat message for which the date and author info is displayed.
289+
/// - Returns: view shown in the date and author indicator slot.
290+
func makeMessageAuthorAndDateView(for message: ChatMessage) -> MessageAuthorAndDateViewType
291+
280292
associatedtype ImageAttachmentViewType: View
281293
/// Creates the image attachment view.
282294
/// - Parameters:

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,28 @@ class ViewFactory_Tests: StreamChatTestCase {
645645
// Then
646646
XCTAssert(modifier is EmptyViewModifier)
647647
}
648+
649+
func test_viewFactory_makeMessageDateView() {
650+
// Given
651+
let viewFactory = DefaultViewFactory.shared
652+
653+
// When
654+
let view = viewFactory.makeMessageDateView(for: message)
655+
656+
// Then
657+
XCTAssert(view is MessageDateView)
658+
}
659+
660+
func test_viewFactory_makeMessageAuthorAndDateView() {
661+
// Given
662+
let viewFactory = DefaultViewFactory.shared
663+
664+
// When
665+
let view = viewFactory.makeMessageAuthorAndDateView(for: message)
666+
667+
// Then
668+
XCTAssert(view is MessageAuthorAndDateView)
669+
}
648670
}
649671

650672
extension ChannelAction: Equatable {

0 commit comments

Comments
 (0)