Messagekit: Different avatar sizes for different indexPaths

Created on 7 Dec 2018  路  8Comments  路  Source: MessageKit/MessageKit

Hi!
How can i set different avatar size for incoming messages for exp. if this messages from admin of group? I mean bigger avatar size for admin than for other users.

I came from version 0.13.2
There was avatarSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize for avatar size

question stale

Most helpful comment

Yeah @Elshad I can definitely see how this got more difficult with MessageKit 1.0+

Technically, we're able to support that old protocol based API again -- I don't think we'll go that direction though. Maybe we can add more methods to the layout object to make this easier 馃

All 8 comments

@Elshad Yeah we changed this in 1.0. Here's how you would do it now:

let adminSize = CGSize(width: 40, height: 40)
if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
  layout.setMessageIncomingAvatarSize(adminSize)
}

@SD10 But this code will set same size to all incoming avatars, i want set different sizes for incoming avatars.
How can i replace below code?
screen shot 2018-12-07 at 17 09 17

Is there easy way to do this like previous version or i must extend MessageSizeCalculator and MessagesCollectionViewFlowLayout?

@Elshad If you want to make this dynamic you probably want to override this function in MessageViewController:

override func collectionView(_ collectionView: UICollectionView, 
                      layout collectionViewLayout: UICollectionViewLayout, 
               sizeForItemAt indexPath: IndexPath) -> CGSize

This method gives you access to the layout object for each index path

@SD10 I has followed extend class way.

screen shot 2018-12-11 at 12 08 14

In viewDidLoad add:
screen shot 2018-12-11 at 12 04 44

Result:
screen shot 2018-12-11 at 11 51 09

If we will use media and location, then we also must extend and add same override functions to MediaMessageSizeCalculator and LocationMessageSizeCalculator.

At now i think this solution is more clear solution

Yeah @Elshad I can definitely see how this got more difficult with MessageKit 1.0+

Technically, we're able to support that old protocol based API again -- I don't think we'll go that direction though. Maybe we can add more methods to the layout object to make this easier 馃

This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 馃檹 Also, feel free to open a new issue if you still experience this problem 馃憤.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omaralbeik picture omaralbeik  路  4Comments

emmanuelay picture emmanuelay  路  3Comments

Leon12345679 picture Leon12345679  路  3Comments

Abacaxi-Nelson picture Abacaxi-Nelson  路  4Comments

adri4silva picture adri4silva  路  4Comments