0

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.

koen
  • 5,383
  • 7
  • 50
  • 89
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • I think you'll need to provide a [mre] for help with this. I ran the Example app included with MessageKit ... set number of "mock" messages to 1500 (1499) ... selected "Advanced Example" ... and logged the calls to `cellForItemAt` -- It was called 48 times. Here's the console output: https://pastebin.com/qGHjmjFW – DonMag Aug 30 '23 at 12:39
  • oh, thank you @DonMag that is quite interesting. First, I will take a look at that. – Bartłomiej Semańczyk Aug 30 '23 at 15:31

0 Answers0