Skip to content

Commit ddfc814

Browse files
committed
feat: MessagesLayoutDelegate method for avatar size
1 parent d4d6c2b commit ddfc814

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Sources/Layout/MessageSizeCalculator.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ open class MessageSizeCalculator: CellSizeCalculator {
164164
}
165165

166166
open func avatarSize(for message: MessageType, at indexPath: IndexPath) -> CGSize {
167+
let layoutDelegate = messagesLayout.messagesLayoutDelegate
168+
let collectionView = messagesLayout.messagesCollectionView
169+
if let size = layoutDelegate.avatarSize(for: message, at: indexPath, in: collectionView) {
170+
return size
171+
}
167172
let dataSource = messagesLayout.messagesDataSource
168173
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
169174
return isFromCurrentSender ? outgoingAvatarSize : incomingAvatarSize

Sources/Protocols/MessagesLayoutDelegate.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ public protocol MessagesLayoutDelegate: AnyObject {
129129
/// alignment from MessageSizeCalculator will be used depending if the message is outgoing or incoming
130130
func messageBottomLabelAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> LabelAlignment?
131131

132+
/// Specifies the size for the `MessageContentCell`'s avatar image view.
133+
/// - Parameters:
134+
/// - message: The `MessageType` that will be displayed for this cell.
135+
/// - indexPath: The `IndexPath` of the cell.
136+
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
137+
/// - Returns: Optional CGSize for the avatar image view. If nil is returned or delegate method is not implemented,
138+
/// size from `MessageSizeCalculator`'s `incomingAvatarSize` or `outgoingAvatarSize` will be used depending if the message is outgoing or incoming
139+
func avatarSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize?
140+
132141
/// Text cell size calculator for messages with MessageType.text.
133142
///
134143
/// - Parameters:
@@ -270,6 +279,10 @@ public extension MessagesLayoutDelegate {
270279
return 0
271280
}
272281

282+
func avatarSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize? {
283+
return nil
284+
}
285+
273286
func messageBottomLabelAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> LabelAlignment? {
274287
return nil
275288
}

0 commit comments

Comments
 (0)