Skip to content

Commit 5035c49

Browse files
committed
[trello.com/c/esjdkfhK] Bug/UI: Extra scroll on many new messages
1 parent ebbbee9 commit 5035c49

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Adamant/Modules/Chat/View/ChatViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,11 @@ private extension ChatViewController {
741741

742742
private extension ChatViewController {
743743
func updateIsScrollPositionNearlyTheBottom() {
744-
let oldValue = isScrollPositionNearlyTheBottom
745744
isScrollPositionNearlyTheBottom = chatMessagesCollectionView.bottomOffset < 150
746-
747-
guard oldValue != isScrollPositionNearlyTheBottom else { return }
748745
}
749746

750747
func updateMessages() {
751-
chatMessagesCollectionView.reloadData(newIds: viewModel.messages.map { $0.id })
748+
chatMessagesCollectionView.reloadData(newIds: viewModel.messages.map { $0.id }, isOnBottom: isScrollPositionNearlyTheBottom)
752749
scrollDownOnNewMessageIfNeeded(previousBottomMessageId: bottomMessageId)
753750
bottomMessageId = viewModel.messages.last?.messageId
754751
}

Adamant/Modules/Chat/View/Subviews/ChatMessagesCollection.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ final class ChatMessagesCollectionView: MessagesCollectionView {
4343
}
4444
}
4545

46-
func reloadData(newIds: [String]) {
47-
guard newIds.last == currentIds.last || newIds.first != currentIds.first else {
46+
func reloadData(newIds: [String], isOnBottom: Bool) {
47+
let hasNewMessagesAtTop = newIds.first != currentIds.first
48+
let hasNewMessagesAtBottom = newIds.last != currentIds.last
49+
50+
guard hasNewMessagesAtTop || hasNewMessagesAtBottom else {
4851
return applyNewIds(newIds)
4952
}
50-
53+
5154
let bottomOffset = self.bottomOffset
5255
applyNewIds(newIds)
53-
setBottomOffset(bottomOffset, safely: !isDragging && !isDecelerating)
56+
57+
if hasNewMessagesAtTop || (hasNewMessagesAtBottom && isOnBottom) {
58+
setBottomOffset(bottomOffset, safely: !isDragging && !isDecelerating)
59+
}
5460
}
5561

5662
func setFullBottomInset(_ inset: CGFloat) {

0 commit comments

Comments
 (0)