Skip to content

Commit 46c013c

Browse files
authored
Merge pull request #2660 from nextcloud/fix/noid/new-message-performance
fix: Performance of new message scroll
2 parents bfdd8f1 + a1f6baa commit 46c013c

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

NextcloudTalk/Chat/ChatViewController.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ import SwiftUI
17201720
self.lastReadMessage = lastReceivedMessage.messageId
17211721
}
17221722
} else {
1723-
tableView.performBatchUpdates {
1723+
let batchUpdates = {
17241724
if !update.insertSections.isEmpty {
17251725
tableView.insertSections(update.insertSections, with: self.newMessageRowAnimation)
17261726
}
@@ -1732,8 +1732,9 @@ import SwiftUI
17321732
if !update.reloadIndexPaths.isEmpty {
17331733
tableView.reloadRows(at: Array(update.reloadIndexPaths), with: .none)
17341734
}
1735+
}
17351736

1736-
} completion: { _ in
1737+
let afterBatchUpdates = {
17371738
// Only scroll to unread message separator if we added it while processing the received messages
17381739
// Otherwise we would scroll whenever a unread message separator is available
17391740
if addedUnreadMessageSeparator, let indexPathUnreadMessageSeparator = self.indexPathForUnreadMessageSeparator() {
@@ -1754,6 +1755,17 @@ import SwiftUI
17541755
self.lastReadMessage = lastReceivedMessage.messageId
17551756
}
17561757
}
1758+
1759+
if self.newMessageRowAnimation == .none {
1760+
// The rows are already in place here, while the completion can be half a second late,
1761+
// showing them behind the textInputbar until the chat finally scrolls
1762+
tableView.performBatchUpdates(batchUpdates, completion: nil)
1763+
afterBatchUpdates()
1764+
} else {
1765+
tableView.performBatchUpdates(batchUpdates) { _ in
1766+
afterBatchUpdates()
1767+
}
1768+
}
17571769
}
17581770

17591771
if firstNewMessagesAfterHistory {

0 commit comments

Comments
 (0)