From b38cde44efc6d8b78e84566ef777f040bf2e67f2 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Wed, 31 Jan 2018 01:48:47 -0600 Subject: [PATCH 1/4] Add .custom(Any) case to MessageData --- .../Controllers/MessagesViewController+DataSource.swift | 2 ++ ...esCollectionViewFlowLayout+MessageContainerView.swift | 2 ++ Sources/Models/MessageData.swift | 9 +++++---- Sources/Models/MessageKitError.swift | 2 ++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/Controllers/MessagesViewController+DataSource.swift b/Sources/Controllers/MessagesViewController+DataSource.swift index 68abe2e0..b1cf8286 100644 --- a/Sources/Controllers/MessagesViewController+DataSource.swift +++ b/Sources/Controllers/MessagesViewController+DataSource.swift @@ -68,6 +68,8 @@ extension MessagesViewController: UICollectionViewDataSource { let cell = messagesCollectionView.dequeueReusableCell(LocationMessageCell.self, for: indexPath) cell.configure(with: message, at: indexPath, and: messagesCollectionView) return cell + case .custom: + fatalError(MessageKitError.customDataUnresolvedCell) } } diff --git a/Sources/Layout/MessagesCollectionViewFlowLayout+MessageContainerView.swift b/Sources/Layout/MessagesCollectionViewFlowLayout+MessageContainerView.swift index c41ce7b1..33125f25 100644 --- a/Sources/Layout/MessagesCollectionViewFlowLayout+MessageContainerView.swift +++ b/Sources/Layout/MessagesCollectionViewFlowLayout+MessageContainerView.swift @@ -108,6 +108,8 @@ extension MessagesCollectionViewFlowLayout { let width = messagesLayoutDelegate.widthForLocation(message: message, at: indexPath, with: maxWidth, in: messagesCollectionView) let height = messagesLayoutDelegate.heightForLocation(message: message, at: indexPath, with: maxWidth, in: messagesCollectionView) messageContainerSize = CGSize(width: width, height: height) + case .custom: + fatalError(MessageKitError.customDataUnresolvedSize) } return messageContainerSize diff --git a/Sources/Models/MessageData.swift b/Sources/Models/MessageData.swift index 1cc13e0d..0fb561ca 100644 --- a/Sources/Models/MessageData.swift +++ b/Sources/Models/MessageData.swift @@ -30,10 +30,10 @@ public enum MessageData { /// A standard text message. /// - /// NOTE: The font used for this message will be the value of the + /// - Note: The font used for this message will be the value of the /// `messageLabelFont` property in the `MessagesCollectionViewFlowLayout` object. /// - /// Tip: Using `MessageData.attributedText(NSAttributedString)` doesn't require you + /// Using `MessageData.attributedText(NSAttributedString)` doesn't require you /// to set this property and results in higher performance. case text(String) @@ -52,14 +52,15 @@ public enum MessageData { /// An emoji message. case emoji(String) + /// A custom message. + case custom(Any) + // MARK: - Not supported yet // case audio(Data) // // case system(String) // -// case custom(Any) -// // case placeholder } diff --git a/Sources/Models/MessageKitError.swift b/Sources/Models/MessageKitError.swift index f26797c4..f10bc172 100644 --- a/Sources/Models/MessageKitError.swift +++ b/Sources/Models/MessageKitError.swift @@ -33,4 +33,6 @@ enum MessageKitError { static let unrecognizedCheckingResult = "Received an unrecognized NSTextCheckingResult.CheckingType" static let couldNotLoadAssetsBundle = "MessageKit: Could not load the assets bundle" static let couldNotCreateAssetsPath = "MessageKit: Could not create path to the assets bundle." + static let customDataUnresolvedCell = "Did not return a cell for MessageData.custom(Any)." + static let customDataUnresolvedSize = "Did not return a size for MessageData.custom(Any)." } From 6c388c0fbfadefef453233d6ff0427cdb1b49981 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Thu, 1 Feb 2018 02:15:22 -0600 Subject: [PATCH 2/4] Make .custom assoc value optional --- Sources/Models/MessageData.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Models/MessageData.swift b/Sources/Models/MessageData.swift index 0fb561ca..a6a47328 100644 --- a/Sources/Models/MessageData.swift +++ b/Sources/Models/MessageData.swift @@ -53,7 +53,7 @@ public enum MessageData { case emoji(String) /// A custom message. - case custom(Any) + case custom(Any?) // MARK: - Not supported yet From 9c85719111a80436701d8c81fae31e2604f89b74 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Thu, 1 Feb 2018 02:18:05 -0600 Subject: [PATCH 3/4] Add CHANGELOG entry for #498 --- CHANGELOG.md | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a6802f6..0d95b5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,27 +8,30 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ### Added -Adds the following methods to `MessagesCollectionViewFlowLayout`: -- `messageLabelInsets(for message: MessageType, at indexPath: IndexPath) -> UIEdgeInsets` -- `messageContainerPadding(for message: MessageType, at indexPath: IndexPath) -> UIEdgeInsets` -- `messageContainerMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` -- `messageContainerSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` -- `cellTopLabelAlignment(for message: MessageType, at indexPath: IndexPath) -> LabelAlignment` -- `cellTopLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` -- `cellTopLabelMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` -- `cellBottomLabelAlignment(for message: MessageType, at indexPath: IndexPath) -> LabelAlignment` -- `cellBottomLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` -- `cellBottomLabelMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` -- `avatarPosition(for message: MessageType, at indexPath: IndexPath) -> AvatarPosition` -- `avatarSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` -- `cellContentHeight(for message: MessageType, at indexPath: IndexPath) -> CGFloat` +- **Breaking Change** Adds `.custom(Any?)` case to `MessageData`. +[#498](https://github.com/MessageKit/MessageKit/pull/498) by [@SD10](https://github.com/SD10). + +- Adds the following methods to `MessagesCollectionViewFlowLayout`: + - `messageLabelInsets(for message: MessageType, at indexPath: IndexPath) -> UIEdgeInsets` + - `messageContainerPadding(for message: MessageType, at indexPath: IndexPath) -> UIEdgeInsets` + - `messageContainerMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` + - `messageContainerSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` + - `cellTopLabelAlignment(for message: MessageType, at indexPath: IndexPath) -> LabelAlignment` + - `cellTopLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` + - `cellTopLabelMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` + - `cellBottomLabelAlignment(for message: MessageType, at indexPath: IndexPath) -> LabelAlignment` + - `cellBottomLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` + - `cellBottomLabelMaxWidth(for message: MessageType, at indexPath: IndexPath) -> CGFloat` + - `avatarPosition(for message: MessageType, at indexPath: IndexPath) -> AvatarPosition` + - `avatarSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` + - `cellContentHeight(for message: MessageType, at indexPath: IndexPath) -> CGFloat` [#491](https://github.com/MessageKit/MessageKit/pull/491) by [@SD10](https://github.com/SD10). -Adds the following methods to `MessageCollectionViewCell`: -- `layoutAvatarView(with attributes: MessagesCollectionViewLayoutAttributes)` -- `layoutMessageContainerView(with attributes: MessagesCollectionViewLayoutAttributes)` -- `layoutTopLabel(with attributes: MessagesCollectionViewLayoutAttributes)` -- `layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes)` +- Adds the following methods to `MessageCollectionViewCell`: + - `layoutAvatarView(with attributes: MessagesCollectionViewLayoutAttributes)` + - `layoutMessageContainerView(with attributes: MessagesCollectionViewLayoutAttributes)` + - `layoutTopLabel(with attributes: MessagesCollectionViewLayoutAttributes)` + - `layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes)` [#491](https://github.com/MessageKit/MessageKit/pull/491) by [@SD10](https://github.com/SD10). ### [[Prerelease] 0.13.1](https://github.com/MessageKit/MessageKit/releases/tag/0.13.1) From 1f563d35538356c6bc5a209cc04f032f354f1054 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Fri, 2 Feb 2018 18:59:17 -0600 Subject: [PATCH 4/4] Add comment for .custom(Any?) --- Sources/Models/MessageData.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Models/MessageData.swift b/Sources/Models/MessageData.swift index a6a47328..2bb72bae 100644 --- a/Sources/Models/MessageData.swift +++ b/Sources/Models/MessageData.swift @@ -53,6 +53,9 @@ public enum MessageData { case emoji(String) /// A custom message. + /// - Note: Using this case requires that you override the following methods and handle this case: + /// - `collectionView(_:cellForItemAt indexPath: IndexPath) -> UICollectionViewCell` + /// - `messageContainerSize(for message: MessageType, at indexPath: IndexPath) -> CGSize` case custom(Any?) // MARK: - Not supported yet