diff --git a/Example/ChatExample.xcodeproj/project.pbxproj b/Example/ChatExample.xcodeproj/project.pbxproj index 32ff41d7..925dea78 100644 --- a/Example/ChatExample.xcodeproj/project.pbxproj +++ b/Example/ChatExample.xcodeproj/project.pbxproj @@ -496,7 +496,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExample; + PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; @@ -510,7 +510,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExample; + PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 63acca1c..eaadd8a1 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ B0655A281F23D71400542A83 /* MessageBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0655A271F23D71400542A83 /* MessageBubble.swift */; }; B0655A2A1F23D77200542A83 /* Sender.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0655A291F23D77200542A83 /* Sender.swift */; }; B0655A2C1F23D81600542A83 /* MessageData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0655A2B1F23D81600542A83 /* MessageData.swift */; }; + B0655A2E1F23D8BC00542A83 /* MessagesCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0655A2D1F23D8BC00542A83 /* MessagesCollectionView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -43,6 +44,7 @@ B0655A271F23D71400542A83 /* MessageBubble.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageBubble.swift; sourceTree = ""; }; B0655A291F23D77200542A83 /* Sender.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sender.swift; sourceTree = ""; }; B0655A2B1F23D81600542A83 /* MessageData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageData.swift; sourceTree = ""; }; + B0655A2D1F23D8BC00542A83 /* MessagesCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesCollectionView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -87,10 +89,11 @@ children = ( B0655A251F23D6C500542A83 /* Avatar.swift */, B0655A271F23D71400542A83 /* MessageBubble.swift */, - 882D75831DE507320033F95F /* MessagesDataSource.swift */, - 888CEBFB1D3FD525005178DE /* MessagesViewController.swift */, B0655A2B1F23D81600542A83 /* MessageData.swift */, 88916B461CF0DFE600469F91 /* MessageType.swift */, + B0655A2D1F23D8BC00542A83 /* MessagesCollectionView.swift */, + 882D75831DE507320033F95F /* MessagesDataSource.swift */, + 888CEBFB1D3FD525005178DE /* MessagesViewController.swift */, B0655A291F23D77200542A83 /* Sender.swift */, 88916B3D1CF0DF5100469F91 /* Info.plist */, 88916B3E1CF0DF5100469F91 /* MessageKit.h */, @@ -222,6 +225,7 @@ B0655A281F23D71400542A83 /* MessageBubble.swift in Sources */, B0655A261F23D6C500542A83 /* Avatar.swift in Sources */, B0655A2A1F23D77200542A83 /* Sender.swift in Sources */, + B0655A2E1F23D8BC00542A83 /* MessagesCollectionView.swift in Sources */, 88916B471CF0DFE600469F91 /* MessageType.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -355,7 +359,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.MessageKit; + PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -376,7 +380,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.MessageKit; + PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Sources/MessagesCollectionView.swift b/Sources/MessagesCollectionView.swift new file mode 100644 index 00000000..77ccc2b1 --- /dev/null +++ b/Sources/MessagesCollectionView.swift @@ -0,0 +1,31 @@ +/* + 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 UIKit + +class MessagesCollectionView: UICollectionView { + + weak var messagesDataSource: MessagesDataSource? + +} diff --git a/Sources/MessagesDataSource.swift b/Sources/MessagesDataSource.swift index d0c308d5..55e3d408 100644 --- a/Sources/MessagesDataSource.swift +++ b/Sources/MessagesDataSource.swift @@ -24,11 +24,13 @@ import UIKit -public protocol MessagesDataSource { +public protocol MessagesDataSource: class { - var currentSender: Sender { get } + var currentSender: Sender { get } // if this is a function we can conform via extension func messageForItem(at indexPath: IndexPath, in collectionView: UICollectionView) -> MessageType + + func numberOfMessages(in collectionView: UICollectionView) -> Int } diff --git a/Sources/MessagesViewController.swift b/Sources/MessagesViewController.swift index 5532d497..66260646 100644 --- a/Sources/MessagesViewController.swift +++ b/Sources/MessagesViewController.swift @@ -26,10 +26,37 @@ import UIKit import Foundation - public class MessagesViewController: UIViewController { + + var messagesCollectionView: MessagesCollectionView? override public func viewDidLoad() { super.viewDidLoad() + messagesCollectionView?.delegate = self + messagesCollectionView?.dataSource = self } + +} + +// MARK: - UICollectionViewDelegate Conformance + +extension MessagesViewController: UICollectionViewDelegate {} + +// MARK: - UICollectionViewDataSource Conformance + +extension MessagesViewController: UICollectionViewDataSource { + + public func numberOfSections(in collectionView: UICollectionView) -> Int { + return messagesCollectionView?.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0 + } + + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + let messageCount = messagesCollectionView?.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0 + return messageCount > 0 ? 1 : 0 + } + + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + return UICollectionViewCell() + } + } diff --git a/Sources/Sender.swift b/Sources/Sender.swift index 40ae8eaa..2f927cf0 100644 --- a/Sources/Sender.swift +++ b/Sources/Sender.swift @@ -31,6 +31,7 @@ public struct Sender { public let displayName: String } +// MARK: - Equatable Conformance extension Sender: Equatable { static public func ==(left: Sender, right: Sender) -> Bool {