Hello,
I am currently using MessageKit (3.1.0)
I am running it on iOS 13.4
Using Swift 5.2.2
I have been testing my application on: an Iphone X and Iphone SE and IPhone 11 through the emulators
The Issue I have been running in is with loading the avatar images for messages. Currently the way my messaging is configured is to have the current user's avatar to be hidden, and the person they are chatting with to have an avatar image. I have been able to get this working, but the issue is that the avatar images appear to only load sporadically and randomly, and as messages are sent by the current user they sometimes just start disappearing. Ideally we would like the behavior to mimic the native iOS messaging app where it only applies the avatar to the end of chunks of messages.
Images Seem to be working:

After a few messages one of the pictures disappears:

Here is a video demoing the issue:
https://imgur.com/a/v9p1TmN
Relevant Code:
//Configure Avatar Size
func avatarSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize {
return .zero
}
//This function shows the avatar
func configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
//If it's current user show current user photo.
if message.sender.senderId == self.docId {
avatarView.loadImageUsingCacheWithUrlString(urlString:self.matchImageURLs[0])
} else {
avatarView.isHidden = true
}
}
Note* The function we use for returning the image is a basic cache function which we know works correctly as it is used throughout the app
I am trying to implement the same thing, and also running into this issue. Seems like something is up with prepareForReuse?
@NikhilAnand1998 Did you try to set the avatarView's isHidden to false when loading an avatar image? When reusing the cell, the isHidden is not reset.
I just tried this and it worked for me. Thanks @martinpucik!
Awesome that was the issue! Thank you so much!! Do you know if there is any feature for grouping messages by a user to only show the avatar on the last message of the group? I'm glad to have this working right now though! Thanks!!
I don't think there is something like that right now, so you would need to implement it by yourself. I'm happy your original question was answered tho!
Most helpful comment
@NikhilAnand1998 Did you try to set the avatarView's isHidden to false when loading an avatar image? When reusing the cell, the isHidden is not reset.