diff --git a/Example/Sources/ConversationViewController.swift b/Example/Sources/ConversationViewController.swift index 1a8448c5..5a1e9cef 100644 --- a/Example/Sources/ConversationViewController.swift +++ b/Example/Sources/ConversationViewController.swift @@ -131,9 +131,9 @@ extension ConversationViewController: MessagesDataSource { } -// MARK: - MessagesDisplayDataSource +// MARK: - MessagesDisplayDelegate -extension ConversationViewController: MessagesDisplayDataSource { +extension ConversationViewController: MessagesDisplayDelegate { func avatar(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> Avatar { return SampleData().getAvatarFor(sender: message.sender) diff --git a/Example/Sources/SampleData.swift b/Example/Sources/SampleData.swift index 50f5c4f8..ebb8ff83 100644 --- a/Example/Sources/SampleData.swift +++ b/Example/Sources/SampleData.swift @@ -88,7 +88,6 @@ struct SampleData { return Dan } - func getAvatarFor(sender: Sender) -> Avatar { switch sender { case Dan: diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 369fef0e..a9784df6 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ B0147C831F5BE9220035B36E /* Bundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C821F5BE9220035B36E /* Bundle+Extensions.swift */; }; B0147C901F5ED0810035B36E /* MessageDateHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C8F1F5ED0810035B36E /* MessageDateHeaderView.swift */; }; B0147C921F6002150035B36E /* MessageKitDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C911F6002140035B36E /* MessageKitDateFormatter.swift */; }; + B0147C961F600E290035B36E /* MessageKit+Availability.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C951F600E290035B36E /* MessageKit+Availability.swift */; }; B015E8191F24623D007EDFB6 /* MessagesCollectionViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = B015E8181F24623D007EDFB6 /* MessagesCollectionViewLayoutAttributes.swift */; }; B015E81F1F259D8E007EDFB6 /* MessageInputBarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B015E81E1F259D8E007EDFB6 /* MessageInputBarDelegate.swift */; }; B01E2DD81F5BBDB800E4FA1C /* MessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B01E2DD71F5BBDB800E4FA1C /* MessageStyle.swift */; }; @@ -86,6 +87,7 @@ B0147C821F5BE9220035B36E /* Bundle+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Extensions.swift"; sourceTree = ""; }; B0147C8F1F5ED0810035B36E /* MessageDateHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageDateHeaderView.swift; sourceTree = ""; }; B0147C911F6002140035B36E /* MessageKitDateFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageKitDateFormatter.swift; sourceTree = ""; }; + B0147C951F600E290035B36E /* MessageKit+Availability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MessageKit+Availability.swift"; sourceTree = ""; }; B015E8181F24623D007EDFB6 /* MessagesCollectionViewLayoutAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesCollectionViewLayoutAttributes.swift; sourceTree = ""; }; B015E81E1F259D8E007EDFB6 /* MessageInputBarDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageInputBarDelegate.swift; sourceTree = ""; }; B01E2DD71F5BBDB800E4FA1C /* MessageStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageStyle.swift; sourceTree = ""; }; @@ -275,6 +277,7 @@ children = ( 88916B3D1CF0DF5100469F91 /* Info.plist */, 88916B3E1CF0DF5100469F91 /* MessageKit.h */, + B0147C951F600E290035B36E /* MessageKit+Availability.swift */, ); name = Supporting; sourceTree = ""; @@ -423,6 +426,7 @@ B01280F31F4E8798004BCD3E /* MessageLabelDelegate.swift in Sources */, 376AD1881F4259D20083072A /* TestMessagesViewControllerModel.swift in Sources */, B0655A2A1F23D77200542A83 /* Sender.swift in Sources */, + B0147C961F600E290035B36E /* MessageKit+Availability.swift in Sources */, B074EE931F35587100ABB8C8 /* MessageHeaderView.swift in Sources */, 376AD1821F4258D80083072A /* TestMessageModel.swift in Sources */, B0655A4D1F244C0600542A83 /* MessageCollectionViewCell.swift in Sources */, diff --git a/Sources/MessageKit+Availability.swift b/Sources/MessageKit+Availability.swift new file mode 100644 index 00000000..39acfe72 --- /dev/null +++ b/Sources/MessageKit+Availability.swift @@ -0,0 +1,28 @@ +/* + MIT License + + Copyright (c) 2017 MessageKit + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import Foundation + +@available(*, deprecated: 0.7.0, message: "Removed in MessageKit 0.7.0. Please use MessagesDisplayDelegate") +public protocol MessagesDisplayDataSource {} diff --git a/Sources/MessageStyle.swift b/Sources/MessageStyle.swift index 82ec17c5..64f6fdc4 100644 --- a/Sources/MessageStyle.swift +++ b/Sources/MessageStyle.swift @@ -70,7 +70,6 @@ public enum MessageStyle { case bubbleTail(TailCorner, TailStyle) case bubbleTailOutline(TailCorner, TailStyle) - // MARK: - Public public var image: UIImage? { diff --git a/Sources/MessagesCollectionViewFlowLayout.swift b/Sources/MessagesCollectionViewFlowLayout.swift index 29328470..01064a04 100644 --- a/Sources/MessagesCollectionViewFlowLayout.swift +++ b/Sources/MessagesCollectionViewFlowLayout.swift @@ -132,7 +132,7 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout { attributes.cellBottomLabelInsets = cellBottomLabelInsets attributes.direction = dataSource.isFromCurrentSender(message: message) ? .outgoing : .incoming - let displayDataSource = dataSource as? MessagesDisplayDataSource + let displayDataSource = dataSource as? MessagesDisplayDelegate let avatarPosition = displayDataSource?.avatarPosition(for: message, at: indexPath, in: messagesCollectionView) ?? .messageBottom // Now we set the origins for the frames using the attributes object that contains the calculated sizes @@ -313,7 +313,7 @@ extension MessagesCollectionViewFlowLayout { private func cellTopLabelHeight(for message: MessageType, at indexPath: IndexPath) -> CGFloat { guard let messagesCollectionView = messagesCollectionView else { return 0 } - guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDataSource else { return 0 } + guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDelegate else { return 0 } guard let topLabelText = displayDataSource.cellTopLabelAttributedText(for: message, at: indexPath) else { return 0 } let availableWidth = cellTopLabelWidth(for: message) - cellTopLabelInsets.left - cellTopLabelInsets.right @@ -360,7 +360,7 @@ extension MessagesCollectionViewFlowLayout { private func cellBottomLabelHeight(for message: MessageType, at indexPath: IndexPath) -> CGFloat { guard let messagesCollectionView = messagesCollectionView else { return 0 } - guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDataSource else { return 0 } + guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDelegate else { return 0 } guard let bottomLabelText = displayDataSource.cellBottomLabelAttributedText(for: message, at: indexPath) else { return 0 } let availableWidth = cellBottomLabelWidth(for: message) - cellBottomLabelInsets.left - cellBottomLabelInsets.right diff --git a/Sources/MessagesDisplayDataSource.swift b/Sources/MessagesDisplayDataSource.swift index 5b8b2ba0..24880991 100644 --- a/Sources/MessagesDisplayDataSource.swift +++ b/Sources/MessagesDisplayDataSource.swift @@ -24,7 +24,7 @@ import Foundation -public protocol MessagesDisplayDataSource: class, MessagesDataSource { +public protocol MessagesDisplayDelegate: class, MessagesDataSource { func textColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor @@ -48,7 +48,7 @@ public protocol MessagesDisplayDataSource: class, MessagesDataSource { } -public extension MessagesDisplayDataSource { +public extension MessagesDisplayDelegate { func textColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor { return isFromCurrentSender(message: message) ? .white : .black diff --git a/Sources/MessagesLayoutDelegate.swift b/Sources/MessagesLayoutDelegate.swift index ee847129..95505bcb 100644 --- a/Sources/MessagesLayoutDelegate.swift +++ b/Sources/MessagesLayoutDelegate.swift @@ -35,7 +35,7 @@ public protocol MessagesLayoutDelegate: class { public extension MessagesLayoutDelegate { func headerViewSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize { - guard let dataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDataSource else { return .zero } + guard let dataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDelegate else { return .zero } let shouldDisplay = dataSource.shouldDisplayHeader(for: message, at: indexPath, in: messagesCollectionView) return shouldDisplay ? CGSize(width: messagesCollectionView.bounds.width, height: 12) : .zero } diff --git a/Sources/MessagesViewController.swift b/Sources/MessagesViewController.swift index 73522983..cefdcf03 100644 --- a/Sources/MessagesViewController.swift +++ b/Sources/MessagesViewController.swift @@ -193,7 +193,7 @@ extension MessagesViewController: UICollectionViewDataSource { let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView) - if let displayDataSource = messagesDataSource as? MessagesDisplayDataSource { + if let displayDataSource = messagesDataSource as? MessagesDisplayDelegate { let messageColor = displayDataSource.backgroundColor(for: message, at: indexPath, in: messagesCollectionView) let messageStyle = displayDataSource.messageStyle(for: message, at: indexPath, in: messagesCollectionView) @@ -220,7 +220,7 @@ extension MessagesViewController: UICollectionViewDataSource { public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { guard let messagesCollectionView = collectionView as? MessagesCollectionView else { return UICollectionReusableView() } - guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDataSource else { return UICollectionReusableView() } + guard let displayDataSource = messagesCollectionView.messagesDataSource as? MessagesDisplayDelegate else { return UICollectionReusableView() } let message = displayDataSource.messageForItem(at: indexPath, in: messagesCollectionView) diff --git a/Tests/MessagesDisplayDataSourceTests.swift b/Tests/MessagesDisplayDataSourceTests.swift index 007114de..c711664a 100644 --- a/Tests/MessagesDisplayDataSourceTests.swift +++ b/Tests/MessagesDisplayDataSourceTests.swift @@ -26,7 +26,7 @@ import XCTest @testable import MessageKit -class MessagesDisplayDataSourceTests: XCTestCase { +class MessagesDisplayDelegateTests: XCTestCase { var testClass: TestMessagesViewControllerModel! var window: UIWindow! diff --git a/Tests/TestMessagesViewControllerModel.swift b/Tests/TestMessagesViewControllerModel.swift index db8f0e4e..b87c8067 100644 --- a/Tests/TestMessagesViewControllerModel.swift +++ b/Tests/TestMessagesViewControllerModel.swift @@ -24,7 +24,7 @@ import Foundation -class TestMessagesViewControllerModel: MessagesViewController, MessagesDisplayDataSource { +class TestMessagesViewControllerModel: MessagesViewController, MessagesDisplayDelegate { var messageList: [TestMessage] = []