Reload collectionView when new message is received

This commit is contained in:
Benoit Martins 2023-03-21 17:29:52 +01:00 committed by QuentinArguillere
parent e4eff6aba9
commit b079d12f0a
3 changed files with 27 additions and 2 deletions

View file

@ -104,6 +104,31 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
}
}
func scrollToBottom(){
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: true)
}
func refreshData(){
let indexBottom = self.collectionView.indexPathsForVisibleItems.sorted().first?.row
let offset = self.collectionView.contentOffset
print("MultilineMessageCell configure \(offset) \(indexBottom)")
collectionView.reloadData()
self.collectionView.scrollToItem(at: IndexPath(row: indexBottom! + 1, section: 0), at: .top, animated: false)
/*
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
let offsetIndex = self.collectionView.contentOffset
print("MultilineMessageCell configure \(offsetIndex)")
self.collectionView.setContentOffset(CGPoint(x: self.collectionView.contentOffset.x, y: self.collectionView.contentOffset.y + offset.y + 10), animated: false)
}
*/
//self.collectionView.scrollToItem(at: IndexPath(item: 1, section: 0), at: .bottom, animated: false)
//DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
// self.scrollToBottom()
//}
}
// MARK: - UICollectionViewDataSource -
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MultilineMessageCell.reuseId, for: indexPath) as! MultilineMessageCell

View file

@ -168,6 +168,8 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll
self.tableController.scrollBadge!.isHidden = false
self.tableController.scrollBadge!.text = "\(ChatConversationViewModel.sharedModel.unread_msg+1)"
}
self.tableControllerSwift.refreshData()
}
ChatConversationViewModel.sharedModel.stateChanged.observe { state in

View file

@ -1175,7 +1175,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
downloadContentCollection[indexTransferProgress]!.downloadButtonLabel.isHidden = true
downloadContentCollection[indexTransferProgress]!.circularProgressBarView.isHidden = false
//downloadContentCollection[indexTransferProgress]!.downloadProgressBar.isHidden = false
}
DispatchQueue.main.async(execute: { [self] in
@ -1189,7 +1188,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
indexTransferProgress = -1
} else {
downloadContentCollection[indexTransferProgress]!.setUpCircularProgressBarView(toValue: p)
//downloadContentCollection[indexTransferProgress]!.downloadProgressBar.setProgress(p, animated: true)
}
})
}