Skip to content

Commit ecdbada

Browse files
Fixed a bug with updates in the navigation bar typing
1 parent dce6300 commit ecdbada

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChannelHeader/ChatChannelHeaderViewModifier.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public struct DefaultChatChannelHeader: ToolbarContent {
3333
VStack(spacing: 2) {
3434
Text(channelNamer(channel, currentUserId) ?? "")
3535
.font(fonts.bodyBold)
36-
if !channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
36+
if !channel.currentlyTypingUsersFiltered(currentUserId: currentUserId).isEmpty
3737
&& utils.typingIndicatorPlacement == .navigationBar {
3838
HStack {
3939
TypingIndicatorView()
40-
SubtitleText(text: channel.typingIndicatorString)
40+
SubtitleText(text: channel.typingIndicatorString(currentUserId: currentUserId))
4141
}
4242
} else {
4343
Text(channel.onlineInfoText(currentUserId: currentUserId))

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
283283

284284
if type != channelHeaderType {
285285
channelHeaderType = type
286+
} else if type == .typingIndicator {
287+
// Toolbar is not updated when new user starts typing.
288+
// Therefore, we shortly update the state to regular to trigger an update.
289+
channelHeaderType = .regular
290+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
291+
self?.channelHeaderType = .typingIndicator
292+
}
286293
}
287294
}
288295
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
149149
if !channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
150150
&& utils.typingIndicatorPlacement == .bottomOverlay {
151151
TypingIndicatorBottomView(
152-
typingIndicatorString: channel.typingIndicatorString
152+
typingIndicatorString: channel.typingIndicatorString(currentUserId: chatClient.currentUserId)
153153
)
154154
}
155155
}

Sources/StreamChatSwiftUI/ChatChannel/Utils/ChatChannelExtensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ extension ChatChannel {
3434
}
3535
}
3636

37-
var typingIndicatorString: String {
38-
let typingUsers = Array(currentlyTypingUsers)
37+
func typingIndicatorString(currentUserId: UserId?) -> String {
38+
let typingUsers = currentlyTypingUsersFiltered(currentUserId: currentUserId)
3939
if let user = typingUsers.first(where: { user in user.name != nil }), let name = user.name {
4040
return L10n.MessageList.TypingIndicator.users(name, typingUsers.count - 1)
4141
} else {

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public struct ChatChannelListItem: View {
8787
} else if !channel.currentlyTypingUsersFiltered(
8888
currentUserId: chatClient.currentUserId
8989
).isEmpty {
90-
return channel.typingIndicatorString
90+
return channel.typingIndicatorString(currentUserId: chatClient.currentUserId)
9191
} else if let latestMessage = channel.latestMessages.first {
9292
return "\(latestMessage.author.name ?? latestMessage.author.id): \(latestMessage.textContent ?? latestMessage.text)"
9393
} else {

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelExtensions_Tests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChatChannelExtensions_Tests: XCTestCase {
2626
let channel = ChatChannel.mockDMChannel()
2727

2828
// When
29-
let typingIndicatorString = channel.typingIndicatorString
29+
let typingIndicatorString = channel.typingIndicatorString(currentUserId: nil)
3030

3131
// Then
3232
XCTAssert(typingIndicatorString == "Someone is typing")
@@ -42,7 +42,7 @@ class ChatChannelExtensions_Tests: XCTestCase {
4242
)
4343

4444
// When
45-
let typingIndicatorString = channel.typingIndicatorString
45+
let typingIndicatorString = channel.typingIndicatorString(currentUserId: nil)
4646

4747
// Then
4848
XCTAssert(typingIndicatorString == "Martin is typing")
@@ -61,7 +61,7 @@ class ChatChannelExtensions_Tests: XCTestCase {
6161
)
6262

6363
// When
64-
let typingIndicatorString = channel.typingIndicatorString
64+
let typingIndicatorString = channel.typingIndicatorString(currentUserId: nil)
6565

6666
// Then
6767
XCTAssert(

0 commit comments

Comments
 (0)