File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
Adamant/Modules/Chat/View Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -741,14 +741,11 @@ private extension ChatViewController {
741741
742742private 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 }
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments