Simply I use MessageKit library for displaying custom chats in my iOS app. But there is an issue I do not know how to resolve.
How works native UICollectionView
on load?
- not every cell is loaded to the view, but only the visible ones and a few more. So, even there is 3k cells, only for some of them will be called for example
willDisplayCell
. And when user scrolls it later... then are called again for coming cells. But it works like the newest on the top, and user scrolls from the bottom to up. And it works...
How works MessageKit collectionView on load?
- EVERY cell is loaded to the view, and for EVERY cell is called
willDisplayCell
on first load which is not what I want. Is there a way to fix it? Maybe the issue is related to the scroll direction, newest at the bottom, and user scrolls from the top to bottom to see oldest cells (messages).
There is nothing complicated in my view:
private func setupView() {
showMessageTimestampOnSwipeLeft = true
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messageCellDelegate = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
messagesCollectionView.delegate = self
}
func messageForItem(at indexPath: IndexPath, in _: MessagesCollectionView) -> MessageType {
viewModel.message(at: indexPath)
}
function from viewModel
:
func message(at indexPath: IndexPath) -> MessageType {
fetchedResultsController!.object(at: indexPath)
}
PS There is no sense to copy all the code just for reproductive example. I am looking for an idea how to solve the issue.