Skip to content

Commit 873fc1a

Browse files
Added method to swap typing indicator view
1 parent 29ec1ab commit 873fc1a

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
217217
}
218218

219219
if shouldShowTypingIndicator {
220-
TypingIndicatorBottomView(
221-
typingIndicatorString: channel.typingIndicatorString(currentUserId: chatClient.currentUserId)
220+
factory.makeTypingIndicatorBottomView(
221+
channel: channel,
222+
currentUserId: chatClient.currentUserId
222223
)
223224
}
224225
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ extension ViewFactory {
435435
DateIndicatorView(date: date)
436436
}
437437

438+
public func makeTypingIndicatorBottomView(
439+
channel: ChatChannel,
440+
currentUserId: UserId?
441+
) -> some View {
442+
let typingIndicatorString = channel.typingIndicatorString(currentUserId: currentUserId)
443+
return TypingIndicatorBottomView(typingIndicatorString: typingIndicatorString)
444+
}
445+
438446
public func makeGiphyBadgeViewType(
439447
for message: ChatMessage,
440448
availableWidth: CGFloat

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,17 @@ public protocol ViewFactory: AnyObject {
443443
/// - Returns: view shown above messages separated by date.
444444
func makeMessageListDateIndicator(date: Date) -> MessageListDateIndicatorViewType
445445

446+
associatedtype TypingIndicatorBottomViewType: View
447+
/// Creates the typing indicator shown at the bottom of a message list.
448+
/// - Parameters:
449+
/// - channel: the channel where the indicator is shown.
450+
/// - currentUserId: the id of the current user.
451+
/// - Returns: view shown in the typing indicator slot.
452+
func makeTypingIndicatorBottomView(
453+
channel: ChatChannel,
454+
currentUserId: UserId?
455+
) -> TypingIndicatorBottomViewType
456+
446457
associatedtype GiphyBadgeViewType: View
447458
/// Creates giphy badge view.
448459
/// If support for more than one custom view is needed, just do if-else check inside the view.

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,20 @@ class ViewFactory_Tests: StreamChatTestCase {
730730
// Then
731731
XCTAssert(view is MessageRepliesView<DefaultViewFactory>)
732732
}
733+
734+
func test_viewFactory_makeTypingIndicatorBottomView() {
735+
// Given
736+
let viewFactory = DefaultViewFactory.shared
737+
738+
// When
739+
let view = viewFactory.makeTypingIndicatorBottomView(
740+
channel: .mockDMChannel(),
741+
currentUserId: nil
742+
)
743+
744+
// Then
745+
XCTAssert(view is TypingIndicatorBottomView)
746+
}
733747
}
734748

735749
extension ChannelAction: Equatable {

0 commit comments

Comments
 (0)