MessagesDataSource
public protocol MessagesDataSource: AnyObject
An object that adopts the MessagesDataSource
protocol is responsible for providing
the data required by a MessagesCollectionView
.
-
The
Sender
of new messages in theMessagesCollectionView
.Declaration
Swift
func currentSender() -> Sender
-
isFromCurrentSender(message:)
Default implementationA helper method to determine if a given message is from the current
Sender
.Default Implementation
Declaration
Swift
func isFromCurrentSender(message: MessageType) -> Bool
Parameters
message
The message to check if it was sent by the current
Sender
. -
The message to be used for a
MessageCollectionViewCell
at the givenIndexPath
.Declaration
Swift
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType
Parameters
indexPath
The
IndexPath
of the cell.messagesCollectionView
The
MessagesCollectionView
in which the message will be displayed. -
The number of sections to be displayed in the
MessagesCollectionView
.Declaration
Swift
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int
Parameters
messagesCollectionView
The
MessagesCollectionView
in which the messages will be displayed. -
numberOfItems(inSection:in:)
Default implementationThe number of cells to be displayed in the
MessagesCollectionView
.Note
The default implementation of this method returns 1. Putting each message in its own section.Default Implementation
Declaration
Swift
func numberOfItems(inSection section: Int, in messagesCollectionView: MessagesCollectionView) -> Int
Parameters
section
The number of the section in which the cells will be displayed.
messagesCollectionView
The
MessagesCollectionView
in which the messages will be displayed. -
cellTopLabelAttributedText(for:at:)
Default implementationThe attributed text to be used for cell’s top label.
The default value returned by this method is
nil
.Default Implementation
Declaration
Swift
func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?
Parameters
message
The
MessageType
that will be displayed by this cell.indexPath
The
IndexPath
of the cell.messagesCollectionView
The
MessagesCollectionView
in which this cell will be displayed. -
messageTopLabelAttributedText(for:at:)
Default implementationThe attributed text to be used for message bubble’s top label.
The default value returned by this method is
nil
.Default Implementation
Declaration
Swift
func messageTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?
Parameters
message
The
MessageType
that will be displayed by this cell.indexPath
The
IndexPath
of the cell.messagesCollectionView
The
MessagesCollectionView
in which this cell will be displayed. -
messageBottomLabelAttributedText(for:at:)
Default implementationThe attributed text to be used for cell’s bottom label.
The default value returned by this method is
nil
.Default Implementation
Declaration
Swift
func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?
Parameters
message
The
MessageType
that will be displayed by this cell.indexPath
The
IndexPath
of the cell.messagesCollectionView
The
MessagesCollectionView
in which this cell will be displayed.