From 17398a2cb2e1240e73ad559deb61438c12ac67b2 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Tue, 27 Mar 2018 01:28:14 -0500 Subject: [PATCH 1/2] Add hook to configure async media on cell --- .../Protocols/MessagesDisplayDelegate.swift | 20 +++++++++++++++++++ Sources/Views/Cells/MediaMessageCell.swift | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/Sources/Protocols/MessagesDisplayDelegate.swift b/Sources/Protocols/MessagesDisplayDelegate.swift index 75d3e72c..3e7dcb4f 100644 --- a/Sources/Protocols/MessagesDisplayDelegate.swift +++ b/Sources/Protocols/MessagesDisplayDelegate.swift @@ -164,6 +164,20 @@ public protocol MessagesDisplayDelegate: AnyObject { /// - messagesCollectionView: The collection view requesting the information /// - Returns: Your customized animation block. func animationBlockForLocation(message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> ((UIImageView) -> Void)? + + // MARK: - Media Messages + + /// Configure the `MediaMessageCell`s `UIImageView`. + /// + /// - Parameters: + /// - imageView: The `UIImageView` of the cell. + /// - 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. + /// - Note: + /// The default implementation of this method does nothing. + func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) + } public extension MessagesDisplayDelegate { @@ -240,4 +254,10 @@ public extension MessagesDisplayDelegate { return nil } + // MARK: - Media Message Defaults + + func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) { + + /* No-op Default */ + } } diff --git a/Sources/Views/Cells/MediaMessageCell.swift b/Sources/Views/Cells/MediaMessageCell.swift index c23eb414..5e922c4a 100644 --- a/Sources/Views/Cells/MediaMessageCell.swift +++ b/Sources/Views/Cells/MediaMessageCell.swift @@ -58,6 +58,11 @@ open class MediaMessageCell: MessageCollectionViewCell { open override func configure(with message: MessageType, at indexPath: IndexPath, and messagesCollectionView: MessagesCollectionView) { super.configure(with: message, at: indexPath, and: messagesCollectionView) + + guard let displayDelegate = messagesCollectionView.messagesDisplayDelegate else { + fatalError(MessageKitError.nilMessagesDisplayDelegate) + } + switch message.data { case .photo(let mediaItem): imageView.image = mediaItem.image ?? mediaItem.placeholderImage @@ -68,5 +73,7 @@ open class MediaMessageCell: MessageCollectionViewCell { default: break } + + displayDelegate.configureMediaMessageImageView(imageView, for: message, at: indexPath, in: messagesCollectionView) } } From 28199f6687127c2bf8f652f8159c5f0d4c57dee6 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Tue, 27 Mar 2018 01:35:46 -0500 Subject: [PATCH 2/2] Add CHANGELOG entry for #592 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1e639b..f925e884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,10 @@ the `MessageData.location` case. - Added new class `InsetLabel`. [#580](https://github.com/MessageKit/MessageKit/pull/580) by [@SD10](https://github.com/sd10). +- Added new method `configureMediaMessageImageView(_:for:at:in)` to configure the `UIImageView` of a +`MediaMessageCell` asynchronously. +[#592](https://github.com/MessageKit/MessageKit/pull/592) by [@zhongwuzw](https://github.com/zhongwuzw), [@SD10](https://github.com/sd10) + ### Changed - **Breaking Change** Changed `LabelAlignment` to be a `struct` with properties of