From e02643ccfae914bd1a66aa2a42a924af78480340 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 09:10:15 +0200 Subject: [PATCH 01/21] Added Pure Layout --- Podfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 1c7c143..3fff448 100644 --- a/Podfile +++ b/Podfile @@ -6,7 +6,10 @@ target 'nMessenger' do use_frameworks! # Pods for nMessenger - pod 'AsyncDisplayKit', '2.2' + pod 'AsyncDisplayKit', '2.2' + + # UI + pod 'PureLayout' target 'nMessengerTests' do inherit! :search_paths From 611736ecbe2d968a7d605a1f7c086605acb9f19b Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 09:24:56 +0200 Subject: [PATCH 02/21] Programmatically created Input Bar View --- .../InputBarView/InputBarView.swift | 7 +- .../InputBarView/NMessengerBarView.swift | 239 +++++++++--------- 2 files changed, 124 insertions(+), 122 deletions(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/InputBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/InputBarView.swift index 9bea4a7..de5937d 100644 --- a/nMessenger/Source/Messenger/Components/InputBarView/InputBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/InputBarView.swift @@ -17,11 +17,8 @@ import UIKit */ open class InputBarView: UIView, InputBarViewProtocol { - //MARK: IBOutlets - //@IBOutlets for input area view - @IBOutlet open weak var textInputAreaView: UIView! - //@IBOutlets for input view - @IBOutlet open weak var textInputView: UITextView! + open var textInputAreaView: UIView = UIView() + open var textInputView: UITextView = UITextView() //MARK: Public Parameters diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 2c2b94f..66c8216 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -11,35 +11,57 @@ import UIKit import AVFoundation import Photos +import PureLayout //MARK: InputBarView +/** + InputBarViewDelegate protocol for NMessenger. + Defines methods to be implemented inorder to use the InputBar + */ +public protocol InputBarViewDelegate : class { + /** + Should define behavior attach button is tapped + */ + func onAttach() +} + /** InputBarView class for NMessenger. Define the input bar for NMessenger. This is where the user would type text and open the camera or photo library. */ -open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelegate { - - //MARK: IBOutlets - //@IBOutlet for InputBarView - @IBOutlet open weak var inputBarView: UIView! - //@IBOutlet for send button - @IBOutlet open weak var sendButton: UIButton! - //@IBOutlets NSLayoutConstraint input area view height - @IBOutlet open weak var textInputAreaViewHeight: NSLayoutConstraint! - //@IBOutlets NSLayoutConstraint input view height - @IBOutlet open weak var textInputViewHeight: NSLayoutConstraint! +open class NMessengerBarView: InputBarView, UITextViewDelegate { //MARK: Public Parameters - //Reference to CameraViewController - open lazy var cameraVC: CameraViewController = CameraViewController() + //InputBarViewDelegate that implemets the delegate methods + open weak var inputBarDelegate: InputBarViewDelegate? + + //Container for all views + open var inputBarView = UIView() + + //Left View providing integration flexibility to change the left input bar buttons + open var leftView: UIView = UIView(forAutoLayout: ()) + + //RightView providing integration flexibility to change the right input bar buttons + open var rightView: UIView = UIView(forAutoLayout: ()) + + //Providing access to send button, to allow integrator to remove it and add custom right view buttons + open var sendButton: UIButton = UIButton() + + //Providing access to attach button, to allow integrator to remove it and add custom left view buttons + open var attachButton: UIButton = UIButton(type: .contactAdd) + + open var textInputAreaViewHeight: NSLayoutConstraint = NSLayoutConstraint() + + open var textInputViewHeight: NSLayoutConstraint = NSLayoutConstraint() + //CGFloat to the fine the number of rows a user can type open var numberOfRows:CGFloat = 3 //String as placeholder text in input view open var inputTextViewPlaceholder: String = "NMessenger" - { + { willSet(newVal) { - self.textInputView.text = newVal + textInputView.text = newVal } } @@ -62,7 +84,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega */ public required init(controller:NMessengerViewController) { super.init(controller: controller) - loadFromBundle() + load() } /** Initialiser the view. @@ -72,7 +94,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega */ public required init(controller:NMessengerViewController,frame: CGRect) { super.init(controller: controller,frame: frame) - loadFromBundle() + load() } /** - parameter aDecoder: Must be NSCoder @@ -80,21 +102,74 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega */ public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - loadFromBundle() + load() } // MARK: Initialiser helper methods /** - Loads the view from nib file InputBarView and does intial setup. + Loads the view constraints and does intial setup. */ - fileprivate func loadFromBundle() { - _ = Bundle(for: NMessengerViewController.self).loadNibNamed("NMessengerBarView", owner: self, options: nil)?[0] as! UIView - self.addSubview(inputBarView) - inputBarView.frame = self.bounds + fileprivate func load() { + + inputBarView.backgroundColor = UIColor.n1LighterGreyColor() + + addSubview(inputBarView) + inputBarView.frame = bounds + + inputBarView.addSubview(textInputAreaView) + textInputAreaView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)) + + rightView.backgroundColor = UIColor.white + leftView.backgroundColor = UIColor.white + + textInputAreaView.addSubview(rightView) + textInputAreaView.addSubview(leftView) + + sendButton.setTitle("Send", for: UIControlState.normal) + sendButton.setTitleColor(UIColor.blue, for: .normal) + sendButton.setTitleColor(UIColor.gray, for: .disabled) + sendButton.backgroundColor = UIColor.white + sendButton.titleLabel?.font = UIFont.systemFont(ofSize: 15) + sendButton.addTarget(self, action: #selector(sendButtonClicked), for: .touchUpInside) + + rightView.addSubview(sendButton) + + attachButton.backgroundColor = UIColor.white + attachButton.titleLabel?.font = UIFont.systemFont(ofSize: 15) + attachButton.addTarget(self, action: #selector(onAttach), for: .touchUpInside) + + leftView.addSubview(attachButton) + textInputView.delegate = self - self.sendButton.isEnabled = false - cameraVC.cameraDelegate = self - + textInputAreaView.addSubview(textInputView) + + sendButton.isEnabled = false + addInputSelectorPlaceholder() + } + + open override func updateConstraints() { + super.updateConstraints() + + inputBarView.autoSetDimension(.height, toSize: 43) + + inputBarView.autoPinEdgesToSuperviewEdges() + + rightView.autoPinEdge(toSuperviewEdge: .top) + rightView.autoPinEdge(toSuperviewEdge: .bottom) + rightView.autoPinEdge(toSuperviewEdge: .right) + + sendButton.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)) + + leftView.autoPinEdge(toSuperviewEdge: .top) + leftView.autoPinEdge(toSuperviewEdge: .bottom) + leftView.autoPinEdge(toSuperviewEdge: .left) + + attachButton.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)) + + textInputView.autoPinEdge(toSuperviewEdge: .top) + textInputView.autoPinEdge(toSuperviewEdge: .bottom) + textInputView.autoPinEdge(.left, to: .right, of: leftView) + textInputView.autoPinEdge(.right, to: .left, of: sendButton) } //MARK: TextView delegate methods @@ -107,7 +182,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega textView.textColor = UIColor.n1DarkestGreyColor() UIView.animate(withDuration: 0.1, animations: { self.sendButton.isEnabled = true - }) + }) DispatchQueue.main.async(execute: { textView.selectedRange = NSMakeRange(0, 0) }); @@ -115,36 +190,36 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega } /** Implementing textViewShouldEndEditing in order to re-add placeholder and hiding send button when lost focus - */ + */ open func textViewShouldEndEditing(_ textView: UITextView) -> Bool { - if self.textInputView.text.isEmpty { - self.addInputSelectorPlaceholder() + if textInputView.text.isEmpty { + addInputSelectorPlaceholder() } UIView.animate(withDuration: 0.1, animations: { self.sendButton.isEnabled = false - }) - self.textInputView.resignFirstResponder() + }) + textInputView.resignFirstResponder() return true } /** Implementing shouldChangeTextInRange in order to remove placeholder when user starts typing and to show send button Re-sizing the text area to default values when the return button is tapped Limit the amount of rows a user can write to the value of numberOfRows - */ + */ open func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if textView.text == "" && (text != "\n") { UIView.animate(withDuration: 0.1, animations: { self.sendButton.isEnabled = true - }) + }) return true } else if (text == "\n") && textView.text != ""{ - if textView == self.textInputView { + if textView == textInputView { textInputViewHeight.constant = textInputViewHeightConst textInputAreaViewHeight.constant = textInputViewHeightConst+10 - _ = self.controller.sendText(self.textInputView.text,isIncomingMessage: false) - self.textInputView.text = "" + _ = controller.sendText(textInputView.text,isIncomingMessage: false) + textInputView.text = "" return false } } @@ -179,9 +254,6 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega textInputViewHeight.constant = newFrame.size.height textInputAreaViewHeight.constant = newFrame.size.height+10 - - - } //MARK: TextView helper methods @@ -189,95 +261,28 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate, CameraViewDelega Adds placeholder text and change the color of textInputView */ fileprivate func addInputSelectorPlaceholder() { - self.textInputView.text = self.inputTextViewPlaceholder - self.textInputView.textColor = UIColor.lightGray + textInputView.text = inputTextViewPlaceholder + textInputView.textColor = UIColor.lightGray } - //MARK: @IBAction selectors + //MARK: selectors /** Send button selector Sends the text in textInputView to the controller */ - @IBAction open func sendButtonClicked(_ sender: AnyObject) { + open func sendButtonClicked() { textInputViewHeight.constant = textInputViewHeightConst textInputAreaViewHeight.constant = textInputViewHeightConst+10 - if self.textInputView.text != "" + if textInputView.text != "" { - _ = self.controller.sendText(self.textInputView.text,isIncomingMessage: false) - self.textInputView.text = "" - } - } - /** - Plus button selector - Requests camera and photo library permission if needed - Open camera and/or photo library to take/select a photo - */ - @IBAction open func plusClicked(_ sender: AnyObject?) { - let authStatus = cameraVC.cameraAuthStatus - let photoLibAuthStatus = cameraVC.photoLibAuthStatus - if(authStatus != AVAuthorizationStatus.authorized) { - cameraVC.isCameraPermissionGranted({(granted) in - if(granted) { - self.cameraVC.cameraAuthStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) - DispatchQueue.main.async(execute: { () -> Void in - self.controller.present(self.cameraVC, animated: true, completion: nil) - }) - } - else - { - self.cameraVC.cameraAuthStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) - if(photoLibAuthStatus != PHAuthorizationStatus.authorized) { - self.cameraVC.requestPhotoLibraryPermissions({ (granted) in - if(granted) { - self.cameraVC.photoLibAuthStatus = PHPhotoLibrary.authorizationStatus() - DispatchQueue.main.async(execute: { () -> Void in - self.controller.present(self.cameraVC, animated: true, completion: - { - ModalAlertUtilities.postGoToSettingToEnableCameraModal(fromController: self.cameraVC) - }) - }) - - } - else - { - self.cameraVC.photoLibAuthStatus = PHPhotoLibrary.authorizationStatus() - ModalAlertUtilities.postGoToSettingToEnableCameraAndLibraryModal(fromController: self.controller) - } - }) - } - else - { - DispatchQueue.main.async(execute: { () -> Void in - self.controller.present(self.cameraVC, animated: true, completion: nil) - }) - } - } - }) - } else {//also check if photo gallery permissions are granted - self.cameraVC.cameraAuthStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) - DispatchQueue.main.async(execute: { () -> Void in - self.controller.present(self.cameraVC, animated: true, completion: nil) - }) + _ = controller.sendText(textInputView.text,isIncomingMessage: false) + textInputView.text = "" } } - - - //MARK: CameraView delegate methods /** - Implemetning CameraView delegate method - Close the CameraView and sends the image to the controller + attachment button selector */ - open func pickedImage(_ image: UIImage!) { - self.cameraVC.dismiss(animated: true, completion: nil) - - _ = self.controller.sendImage(image,isIncomingMessage: false) + open func onAttach() { + inputBarDelegate?.onAttach() } - /** - Implemetning CameraView delegate method - Close the CameraView - */ - open func cameraCancelSelection() { - cameraVC.dismiss(animated: true, completion: nil) - } - } From 8ee80f8a1cbbfc33a6379d507762a68ce566a4a6 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 09:25:12 +0200 Subject: [PATCH 03/21] Removed xib Bar view --- nMessenger.xcodeproj/project.pbxproj | 6 - .../InputBarView/NMessengerBarView.xib | 109 ------------------ 2 files changed, 115 deletions(-) delete mode 100755 nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.xib diff --git a/nMessenger.xcodeproj/project.pbxproj b/nMessenger.xcodeproj/project.pbxproj index 5a53913..d104f48 100755 --- a/nMessenger.xcodeproj/project.pbxproj +++ b/nMessenger.xcodeproj/project.pbxproj @@ -27,7 +27,6 @@ 616280351D8197B700D1F510 /* InputBarViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13F39E01D650D490021A858 /* InputBarViewProtocol.swift */; }; 616280361D8197BA00D1F510 /* InputBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14C8B681D66273700F8616F /* InputBarView.swift */; }; 616280371D8197BE00D1F510 /* NMessengerBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87361D63813700F3C21C /* NMessengerBarView.swift */; }; - 616280381D8197CA00D1F510 /* NMessengerBarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F1FC87371D63813700F3C21C /* NMessengerBarView.xib */; }; 616280461D81A5E700D1F510 /* AsyncDisplayKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 616280451D81A5E700D1F510 /* AsyncDisplayKit.framework */; }; 616280471D81A71500D1F510 /* BubbleConfigurationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87101D63813700F3C21C /* BubbleConfigurationProtocol.swift */; }; 616280481D81A71500D1F510 /* ImageBubbleConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87111D63813700F3C21C /* ImageBubbleConfiguration.swift */; }; @@ -356,7 +355,6 @@ F1FC87CC1D63813700F3C21C /* MessageNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87311D63813700F3C21C /* MessageNode.swift */; }; F1FC87CD1D63813700F3C21C /* CameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87341D63813700F3C21C /* CameraViewController.swift */; }; F1FC87CE1D63813700F3C21C /* NMessengerBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87361D63813700F3C21C /* NMessengerBarView.swift */; }; - F1FC87CF1D63813700F3C21C /* NMessengerBarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F1FC87371D63813700F3C21C /* NMessengerBarView.xib */; }; F1FC87D01D63813700F3C21C /* NMessenger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87381D63813700F3C21C /* NMessenger.swift */; }; F1FC87D11D63813700F3C21C /* NMessengerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC87391D63813700F3C21C /* NMessengerViewController.swift */; }; F1FC87D21D63813700F3C21C /* ModalAlertUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FC873B1D63813700F3C21C /* ModalAlertUtilities.swift */; }; @@ -581,7 +579,6 @@ F1FC87311D63813700F3C21C /* MessageNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageNode.swift; sourceTree = ""; }; F1FC87341D63813700F3C21C /* CameraViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = ""; }; F1FC87361D63813700F3C21C /* NMessengerBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessengerBarView.swift; sourceTree = ""; }; - F1FC87371D63813700F3C21C /* NMessengerBarView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NMessengerBarView.xib; sourceTree = ""; }; F1FC87381D63813700F3C21C /* NMessenger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessenger.swift; sourceTree = ""; }; F1FC87391D63813700F3C21C /* NMessengerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessengerViewController.swift; sourceTree = ""; }; F1FC873B1D63813700F3C21C /* ModalAlertUtilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalAlertUtilities.swift; sourceTree = ""; }; @@ -1100,7 +1097,6 @@ F13F39E01D650D490021A858 /* InputBarViewProtocol.swift */, F14C8B681D66273700F8616F /* InputBarView.swift */, F1FC87361D63813700F3C21C /* NMessengerBarView.swift */, - F1FC87371D63813700F3C21C /* NMessengerBarView.xib */, ); path = InputBarView; sourceTree = ""; @@ -1398,7 +1394,6 @@ 616280A51D81B81C00D1F510 /* loadBubble_0020_Layer-19@2x.png in Resources */, 616280BB1D81B82800D1F510 /* loadBubble_0003_Layer-36@3x.png in Resources */, 616280AD1D81B81C00D1F510 /* loadBubble_0028_Layer-11@2x.png in Resources */, - 616280381D8197CA00D1F510 /* NMessengerBarView.xib in Resources */, 616280701D81B81400D1F510 /* loadBubble_0006_Layer-33@1x.png in Resources */, 616280881D81B81400D1F510 /* loadBubble_0030_Layer-9@1x.png in Resources */, ); @@ -1426,7 +1421,6 @@ F1FC874D1D63813700F3C21C /* loadBubble_0012_Layer-27@1x.png in Resources */, F1FC87A31D63813700F3C21C /* loadBubble_0020_Layer-19@3x.png in Resources */, F1FC87701D63813700F3C21C /* loadBubble_0008_Layer-31@2x.png in Resources */, - F1FC87CF1D63813700F3C21C /* NMessengerBarView.xib in Resources */, F1FC87431D63813700F3C21C /* loadBubble_0002_Layer-37@1x.png in Resources */, F1FC87A01D63813700F3C21C /* loadBubble_0017_Layer-22@3x.png in Resources */, F1FC87A61D63813700F3C21C /* loadBubble_0023_Layer-16@3x.png in Resources */, diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.xib b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.xib deleted file mode 100755 index e983878..0000000 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.xib +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From a825a2c8ff3b2a1b972aa8c394a8b3449cf0edb4 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 09:55:23 +0200 Subject: [PATCH 04/21] added PureLayout dependency --- NMessenger.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/NMessenger.podspec b/NMessenger.podspec index bfdde05..26e3303 100644 --- a/NMessenger.podspec +++ b/NMessenger.podspec @@ -134,4 +134,5 @@ NMessenger is a fast, lightweight messenger component built on AsyncDisplaykit a # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } s.dependency "AsyncDisplayKit", "2.2" + s.dependency "PureLayout" end From 6d70f72bcb8a68c5f6782852a803e0fd735080f0 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 12:57:41 +0200 Subject: [PATCH 05/21] auto pinned to wrong view --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 66c8216..d4f1871 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -169,7 +169,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { textInputView.autoPinEdge(toSuperviewEdge: .top) textInputView.autoPinEdge(toSuperviewEdge: .bottom) textInputView.autoPinEdge(.left, to: .right, of: leftView) - textInputView.autoPinEdge(.right, to: .left, of: sendButton) + textInputView.autoPinEdge(.right, to: .left, of: rightView) } //MARK: TextView delegate methods From 10f56ec608a4d88dc9d110943b62076901ad000b Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 15:04:00 +0200 Subject: [PATCH 06/21] Added Send text delegate method --- .../Components/InputBarView/NMessengerBarView.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index d4f1871..566164f 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -23,6 +23,11 @@ public protocol InputBarViewDelegate : class { Should define behavior attach button is tapped */ func onAttach() + + /** + Should define behavior when send button is tapped + */ + func onSendText() } /** @@ -276,6 +281,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { if textInputView.text != "" { _ = controller.sendText(textInputView.text,isIncomingMessage: false) + inputBarDelegate?.onSendText() textInputView.text = "" } } From 44f39958ac33dec04aec1bdea4cb8e9c8bb4d226 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Mon, 27 Mar 2017 15:31:47 +0200 Subject: [PATCH 07/21] Added variable --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 566164f..e5a40d9 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -27,7 +27,7 @@ public protocol InputBarViewDelegate : class { /** Should define behavior when send button is tapped */ - func onSendText() + func onSendText(_ text: String) } /** @@ -281,7 +281,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { if textInputView.text != "" { _ = controller.sendText(textInputView.text,isIncomingMessage: false) - inputBarDelegate?.onSendText() + inputBarDelegate?.onSendText(textInputView.text) textInputView.text = "" } } From 0566dd7b1c74bb8d17a28daf6a4b5be6179993ce Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Wed, 29 Mar 2017 12:15:21 +0200 Subject: [PATCH 08/21] Update for Xcode 8.3 --- nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift | 6 +++--- nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift b/nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift index 75af9e5..abcb2ab 100755 --- a/nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift +++ b/nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift @@ -64,10 +64,10 @@ open class DefaultBubble: Bubble { path = CGMutablePath() - path.addArc(center: CGPoint(x: rect.maxX, y: rect.minY), radius: radius2, startAngle: CGFloat(-M_PI_2), endAngle: 0, clockwise: false) + path.addArc(center: CGPoint(x: rect.maxX, y: rect.minY), radius: radius2, startAngle: CGFloat(-Double.pi/2), endAngle: 0, clockwise: false) path.addLine(to: CGPoint(x: rect.maxX + radius2, y: rect.maxY + radius2)) - path.addArc(center: CGPoint(x: rect.minX, y: rect.maxY), radius: radius2, startAngle: CGFloat(M_PI_2), endAngle: CGFloat(M_PI), clockwise: false) - path.addArc(center: CGPoint(x: rect.minX, y: rect.minY), radius: radius2, startAngle: CGFloat(M_PI), endAngle: CGFloat(-M_PI_2), clockwise: false) + path.addArc(center: CGPoint(x: rect.minX, y: rect.maxY), radius: radius2, startAngle: CGFloat(Double.pi/2), endAngle: CGFloat(Double.pi), clockwise: false) + path.addArc(center: CGPoint(x: rect.minX, y: rect.minY), radius: radius2, startAngle: CGFloat(Double.pi), endAngle: CGFloat(-Double.pi/2), clockwise: false) //CGPathAddArc(path, nil, rect.maxX, rect.minY, radius2, CGFloat(-M_PI_2), 0, false) //CGPathAddLineToPoint(path, nil, rect.maxX + radius2, rect.maxY + radius2) diff --git a/nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift b/nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift index 86e84f4..e264b09 100755 --- a/nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift +++ b/nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift @@ -63,8 +63,8 @@ open class StackedBubble: Bubble { path.move(to: CGPoint(x: rect.minX, y: rect.minY - radius2)) path.addLine(to: CGPoint(x: rect.maxX + radius2, y: rect.minY - radius2)) path.addLine(to: CGPoint(x: rect.maxX + radius2, y: rect.maxY + radius2)) - path.addArc(center: CGPoint(x: rect.minX, y: rect.maxY), radius: radius2, startAngle: CGFloat(M_PI_2), endAngle: CGFloat(M_PI), clockwise: false) - path.addArc(center: CGPoint(x: rect.minX, y: rect.minY), radius: radius2, startAngle: CGFloat(M_PI), endAngle: CGFloat(-M_PI_2), clockwise: false) + path.addArc(center: CGPoint(x: rect.minX, y: rect.maxY), radius: radius2, startAngle: CGFloat(Double.pi/2), endAngle: CGFloat(Double.pi), clockwise: false) + path.addArc(center: CGPoint(x: rect.minX, y: rect.minY), radius: radius2, startAngle: CGFloat(Double.pi), endAngle: CGFloat(-(Double.pi/2)), clockwise: false) //CGPathMoveToPoint(path, nil, rect.minX, rect.minY - radius2) //CGPathAddLineToPoint(path, nil, rect.maxX + radius2, rect.minY - radius2) From 4cca381775f789b15a0e433708cc81dbd3f6fae3 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Wed, 29 Mar 2017 14:29:57 +0200 Subject: [PATCH 09/21] Updated Delegate implementation --- .../InputBarView/NMessengerBarView.swift | 3 +- .../Messenger/NMessengerViewController.swift | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index e5a40d9..d864752 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -20,7 +20,7 @@ import PureLayout */ public protocol InputBarViewDelegate : class { /** - Should define behavior attach button is tapped + Should define behavior when attach button is tapped */ func onAttach() @@ -280,7 +280,6 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { textInputAreaViewHeight.constant = textInputViewHeightConst+10 if textInputView.text != "" { - _ = controller.sendText(textInputView.text,isIncomingMessage: false) inputBarDelegate?.onSendText(textInputView.text) textInputView.text = "" } diff --git a/nMessenger/Source/Messenger/NMessengerViewController.swift b/nMessenger/Source/Messenger/NMessengerViewController.swift index 00ce354..a56971e 100755 --- a/nMessenger/Source/Messenger/NMessengerViewController.swift +++ b/nMessenger/Source/Messenger/NMessengerViewController.swift @@ -35,7 +35,7 @@ fileprivate func >= (lhs: T?, rhs: T?) -> Bool { } -open class NMessengerViewController: UIViewController, UITextViewDelegate, NMessengerDelegate, UIGestureRecognizerDelegate { +open class NMessengerViewController: UIViewController { //MARK: Views //This is messenger view @@ -153,7 +153,9 @@ open class NMessengerViewController: UIViewController, UITextViewDelegate, NMess */ open func getInputBar() -> InputBarView { - return NMessengerBarView(controller: self) + let bar = NMessengerBarView(controller: self) + bar.inputBarDelegate = self + return bar } /** Adds auto layout constraints for NMessenger and InputBarView @@ -551,3 +553,40 @@ open class NMessengerViewController: UIViewController, UITextViewDelegate, NMess } } + +extension NMessengerViewController: NMessengerDelegate { + +} + +extension NMessengerViewController: InputBarViewDelegate { + /** + Should define behavior when attach button is tapped + */ + public func onAttach() { + let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) + + actionSheet.addAction(UIAlertAction( + title: "Take photo", + style: UIAlertActionStyle.default, + handler: { _ in })) + + actionSheet.addAction(UIAlertAction( + title: "Upload from gallery", + style: UIAlertActionStyle.default, + handler: { _ in })) + + actionSheet.addAction(UIAlertAction( + title: "Cancel", + style: .cancel, + handler: { _ in })) + + self.present(actionSheet, animated: true, completion: nil) + } + + /** + Should define behavior when send button is tapped + */ + public func onSendText(_ text: String) { + _ = self.sendText(text,isIncomingMessage: false) + } +} From aa1df7077bae683e3e84979c8f4e0096f4090de9 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 09:58:22 +0200 Subject: [PATCH 10/21] Added property for primary bubble position --- .../MessageCell/MessageGroup.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift index 8423c37..3cde2d6 100755 --- a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift +++ b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift @@ -25,6 +25,12 @@ open class MessageGroup: GeneralMessengerCell { case none } + /** Used for current state of avatar display position, on first or last message */ + public enum PrimaryBubblePosition { + case first + case last + } + // MARK: Public Variables open weak var delegate: MessageCellProtocol? /** Holds a table of GeneralMessengerCells*/ @@ -37,6 +43,8 @@ open class MessageGroup: GeneralMessengerCell { open var animationDelay: TimeInterval = 0 /** Avatar new message animation speed */ open var avatarAnimationSpeed: TimeInterval = 0.15 + /** Avatar display position*/ + open var primaryBubblePosition: PrimaryBubblePosition = .first /** Spacing around the avatar @@ -395,7 +403,7 @@ open class MessageGroup: GeneralMessengerCell { message.currentTableNode = self.messageTable //message specific UI - if messages.first == nil { //will be the first message + if isPrimaryBubblePosition(message) { //will be the avatar display position message.cellPadding = UIEdgeInsets.zero if let message = message as? MessageNode { message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() @@ -414,6 +422,15 @@ open class MessageGroup: GeneralMessengerCell { } } + fileprivate func isPrimaryBubblePosition(_ message: GeneralMessengerCell) -> Bool { + switch primaryBubblePosition { + case .first: + return messages.first == nil + case .last: + return messages.last == nil + } + } + /** Calls and resets the layout completion block */ fileprivate func callLayoutCompletionBlock() { From 892fa78ff78ebf119a4a5021da383d498fc47c9b Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 09:58:56 +0200 Subject: [PATCH 11/21] Implemented messenger bar delegate --- nMessenger/Source/Messenger/NMessengerViewController.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nMessenger/Source/Messenger/NMessengerViewController.swift b/nMessenger/Source/Messenger/NMessengerViewController.swift index a56971e..b3fbe65 100755 --- a/nMessenger/Source/Messenger/NMessengerViewController.swift +++ b/nMessenger/Source/Messenger/NMessengerViewController.swift @@ -114,7 +114,6 @@ open class NMessengerViewController: UIViewController { */ override open func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = UIColor.white //load views loadMessengerView() loadInputView() @@ -562,7 +561,7 @@ extension NMessengerViewController: InputBarViewDelegate { /** Should define behavior when attach button is tapped */ - public func onAttach() { + open func onAttach() { let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) actionSheet.addAction(UIAlertAction( @@ -586,7 +585,7 @@ extension NMessengerViewController: InputBarViewDelegate { /** Should define behavior when send button is tapped */ - public func onSendText(_ text: String) { + open func onSendText(_ text: String) { _ = self.sendText(text,isIncomingMessage: false) } } From a8a1580449071254660015ef775fb2fd6e9a6597 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 12:03:02 +0200 Subject: [PATCH 12/21] updated text input area view constraints --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index d864752..4693ca6 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -122,7 +122,6 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { inputBarView.frame = bounds inputBarView.addSubview(textInputAreaView) - textInputAreaView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)) rightView.backgroundColor = UIColor.white leftView.backgroundColor = UIColor.white @@ -154,11 +153,12 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { open override func updateConstraints() { super.updateConstraints() - inputBarView.autoSetDimension(.height, toSize: 43) inputBarView.autoPinEdgesToSuperviewEdges() + textInputAreaView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)) + rightView.autoPinEdge(toSuperviewEdge: .top) rightView.autoPinEdge(toSuperviewEdge: .bottom) rightView.autoPinEdge(toSuperviewEdge: .right) From 57f27c8b1fec43fcd0875c6b2188537eb561adab Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 15:50:41 +0200 Subject: [PATCH 13/21] Fixed primary bubble position --- .../MessageCell/MessageGroup.swift | 76 +++++++++++++------ 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift index 3cde2d6..5d19971 100755 --- a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift +++ b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift @@ -402,32 +402,62 @@ open class MessageGroup: GeneralMessengerCell { fileprivate func updateMessage(_ message: GeneralMessengerCell) { message.currentTableNode = self.messageTable - //message specific UI - if isPrimaryBubblePosition(message) { //will be the avatar display position - message.cellPadding = UIEdgeInsets.zero - if let message = message as? MessageNode { - message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() - message.isIncomingMessage = self.isIncomingMessage - //set the offset to 0 to prevent spacing issues - message.messageOffset = 0 - } - } else { - message.cellPadding = UIEdgeInsets(top: 4, left: 0, bottom: 0, right: 0) - if let message = message as? MessageNode { - message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getSecondaryBubble() - message.isIncomingMessage = self.isIncomingMessage - //set the offset to 0 to prevent spacing issues - message.messageOffset = 0 - } - } - } - - fileprivate func isPrimaryBubblePosition(_ message: GeneralMessengerCell) -> Bool { switch primaryBubblePosition { case .first: - return messages.first == nil + //message specific UI + if messages.first == nil { + message.cellPadding = UIEdgeInsets.zero + if let message = message as? MessageNode { + message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() + message.isIncomingMessage = self.isIncomingMessage + //set the offset to 0 to prevent spacing issues + message.messageOffset = 0 + } + } else { + message.cellPadding = UIEdgeInsets(top: 4, left: 0, bottom: 0, right: 0) + if let message = message as? MessageNode { + message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getSecondaryBubble() + message.isIncomingMessage = self.isIncomingMessage + //set the offset to 0 to prevent spacing issues + message.messageOffset = 0 + } + } + break case .last: - return messages.last == nil + if !messages.isEmpty { + let lastIndex = messages.count - 1 + let oldMessage = self.messages[lastIndex] + //set state + self.state = .replaced + if let message = oldMessage as? MessageNode { + let isIncoming = message.isIncomingMessage + message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getSecondaryBubble() + message.isIncomingMessage = isIncoming + //set the offset to 0 to prevent spacing issues + message.messageOffset = 0 + } + + self.messageTable.reloadRows(at: [IndexPath(row: lastIndex, section: 0) ], with: .fade) + + message.cellPadding = UIEdgeInsets.zero + if let message = message as? MessageNode { + message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() + message.isIncomingMessage = self.isIncomingMessage + //set the offset to 0 to prevent spacing issues + message.messageOffset = 0 + } + + } else if messages.first == nil { + message.cellPadding = UIEdgeInsets.zero + if let message = message as? MessageNode { + message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() + message.isIncomingMessage = self.isIncomingMessage + //set the offset to 0 to prevent spacing issues + message.messageOffset = 0 + } + } + + break } } From 38ee9dc20acee87f988d3fcacc3333e30852508d Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 15:57:11 +0200 Subject: [PATCH 14/21] Added Send to return keyboard --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 4693ca6..1ef3184 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -223,7 +223,7 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { if textView == textInputView { textInputViewHeight.constant = textInputViewHeightConst textInputAreaViewHeight.constant = textInputViewHeightConst+10 - _ = controller.sendText(textInputView.text,isIncomingMessage: false) + sendButtonClicked() textInputView.text = "" return false } From efe0b2907a7d878f915b186a0e279af99d8fc7d2 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Thu, 30 Mar 2017 16:01:51 +0200 Subject: [PATCH 15/21] Review changes --- nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift index 5d19971..bcf8f89 100755 --- a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift +++ b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift @@ -447,7 +447,7 @@ open class MessageGroup: GeneralMessengerCell { message.messageOffset = 0 } - } else if messages.first == nil { + } else { message.cellPadding = UIEdgeInsets.zero if let message = message as? MessageNode { message.contentNode?.backgroundBubble = message.contentNode?.bubbleConfiguration.getBubble() From 5fc31ff3e8178aee15afdc10fffd95d3fef84418 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Fri, 31 Mar 2017 09:02:21 +0200 Subject: [PATCH 16/21] Removed resetting of input bar. --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 1ef3184..0b9ccf5 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -224,7 +224,6 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { textInputViewHeight.constant = textInputViewHeightConst textInputAreaViewHeight.constant = textInputViewHeightConst+10 sendButtonClicked() - textInputView.text = "" return false } } From b8666c777b9a6dd679e64592973d75ca1b98d5b9 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Fri, 31 Mar 2017 11:53:39 +0200 Subject: [PATCH 17/21] Updated Delegate call --- .../Messenger/Components/InputBarView/NMessengerBarView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift index 0b9ccf5..e1acad2 100755 --- a/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift +++ b/nMessenger/Source/Messenger/Components/InputBarView/NMessengerBarView.swift @@ -223,7 +223,8 @@ open class NMessengerBarView: InputBarView, UITextViewDelegate { if textView == textInputView { textInputViewHeight.constant = textInputViewHeightConst textInputAreaViewHeight.constant = textInputViewHeightConst+10 - sendButtonClicked() + inputBarDelegate?.onSendText(textInputView.text) + textInputView.text = "" return false } } From c1a10108b5c9a5565e22525328173998a38d1f93 Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Wed, 5 Apr 2017 09:05:20 +0200 Subject: [PATCH 18/21] Added Add message with index --- .../Messenger/Components/NMessenger.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nMessenger/Source/Messenger/Components/NMessenger.swift b/nMessenger/Source/Messenger/Components/NMessenger.swift index f1397fe..ce07579 100755 --- a/nMessenger/Source/Messenger/Components/NMessenger.swift +++ b/nMessenger/Source/Messenger/Components/NMessenger.swift @@ -188,6 +188,22 @@ open class NMessenger: UIView { self.addMessages(messages, atIndex: self.state.itemCount, scrollsToMessage: scrollsToMessage, animation: animation, completion: completion) } } + + /** + Adds an array of messages to the messenger. + - parameter messages: An array of messages + - parameter index: an index in the tableview at which to start adding messages + - parameter scrollsToMessage: If marked true, the tableview will scroll to the newly added + - parameter animation: An animation for newly added cell message + */ + + open func addMessages(_ messages: [GeneralMessengerCell], atIndex index: Int, scrollsToMessage: Bool, animation: UITableViewRowAnimation) { + self.waitForMessageLock { + self.addMessages(messages, atIndex: index, scrollsToMessage: scrollsToMessage, animation: animation, completion: nil) + } + } + + /** Adds batch fetched messages to the head of the messenger. This **MUST BE** called to end a batch fetch operation. (Fire and forget) If no data was received, use an empty array for messages. Calling this outside when a batch fetch has not @@ -436,7 +452,7 @@ open class NMessenger: UIView { Adds messages at a particular index. Updates *currentTableNode* - parameter messages: An array of messages - -parameter index: an index in the tableview at which to start adding messages + - parameter index: an index in the tableview at which to start adding messages - parameter scrollsToMessage: If marked true, the tableview will scroll to the newly added message */ From 7e778bb2f8430fd2d08e5a9ae525da5a60285deb Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Wed, 5 Apr 2017 09:17:20 +0200 Subject: [PATCH 19/21] Version bump --- NMessenger.podspec | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NMessenger.podspec b/NMessenger.podspec index 26e3303..0cfeafa 100644 --- a/NMessenger.podspec +++ b/NMessenger.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "NMessenger" - s.version = "1.0.80" + s.version = "1.0.81" s.summary = "A fast, lightweight messenger component built on AsyncDisplaykit and written in Swift" # This description is used to generate tags and improve search results. diff --git a/README.md b/README.md index 6b896d4..dfa8c75 100755 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Built-in support for: ## Installation for [Cocoapods](https://cocoapods.org) ```ruby -# For latest release in cocoapods - 1.0.80 (Swift 3, ASDK 2.X) +# For latest release in cocoapods - 1.0.81 (Swift 3.1, ASDK 2.x) pod 'NMessenger' # For ASDK 1.9 From 142ffb5045c0144ff59e32fb8be082bdc8ad5d7b Mon Sep 17 00:00:00 2001 From: Wesley Buck Date: Wed, 5 Apr 2017 11:18:20 +0200 Subject: [PATCH 20/21] addMessageToGroup with index --- .../MessageCell/MessageGroup.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift index bcf8f89..a4b1825 100755 --- a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift +++ b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift @@ -307,6 +307,30 @@ open class MessageGroup: GeneralMessengerCell { } } + /** + Add a message to this group + - parameter message: the message to add + - parameter index: an index at which to start adding messages + - parameter layoutCompletionBlock: The block to be called once the new node has been added + */ + open func addMessageToGroup(_ message: GeneralMessengerCell, atIndex index: Int, completion: (()->Void)?) { + self.updateMessage(message) + self.layoutCompletionBlock = completion + + //if the component is already on the screen + if self.hasLaidOut { + let indexPath = IndexPath(row: index, section:0) + //set state + self.state = .added(index: indexPath) + //update table DS + self.messages.insert(message, at: index) + //transition avatar + tableview cells + self.transitionLayout(withAnimation: true, shouldMeasureAsync: false, measurementCompletion: nil) + } else { + self.messages.insert(message, at: index) + } + } + /** If the message exists in the group, it will be replaced with the new message. **Unimplemented** - parameter message: The message to replace From bca7ebafa98cb58d236338a16719d5eaf97d1b92 Mon Sep 17 00:00:00 2001 From: phlippieb Date: Wed, 5 Apr 2017 12:51:10 +0200 Subject: [PATCH 21/21] Batch-add messages to groups --- .../MessageCell/MessageGroup.swift | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift index a4b1825..914f560 100755 --- a/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift +++ b/nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift @@ -19,7 +19,7 @@ open class MessageGroup: GeneralMessengerCell { /** Used for current state of new/old messages*/ public enum MessageGroupState { - case added(index: IndexPath) + case added(indexes: [IndexPath]) case removed case replaced case none @@ -187,7 +187,7 @@ open class MessageGroup: GeneralMessengerCell { override open func animateLayoutTransition(_ context: ASContextTransitioning) { if let state = self.state { switch(state) { - case .added(let indexPath): + case .added(let indexPaths): if let _ = self.avatarNode { self.avatarNode?.frame = context.initialFrame(for: self.avatarNode!) } @@ -214,7 +214,7 @@ open class MessageGroup: GeneralMessengerCell { let time: DispatchTime = DispatchTime.now() + Double(Int64(self.tableviewAnimationDelay)*1000 * Int64(NSEC_PER_MSEC)) / Double(NSEC_PER_SEC) DispatchQueue.main.asyncAfter(deadline: time) { self.messageTable.performBatch(animated: true, updates: { - self.messageTable.insertRows(at: [indexPath], with: .fade) + self.messageTable.insertRows(at: indexPaths, with: .fade) }, completion: { (finished) in }) } @@ -297,7 +297,7 @@ open class MessageGroup: GeneralMessengerCell { if self.hasLaidOut { let indexPath = IndexPath(row: self.messages.count, section:0) //set state - self.state = .added(index: indexPath) + self.state = .added(indexes: [indexPath]) //update table DS self.messages.append(message) //transition avatar + tableview cells @@ -321,7 +321,7 @@ open class MessageGroup: GeneralMessengerCell { if self.hasLaidOut { let indexPath = IndexPath(row: index, section:0) //set state - self.state = .added(index: indexPath) + self.state = .added(indexes: [indexPath]) //update table DS self.messages.insert(message, at: index) //transition avatar + tableview cells @@ -331,6 +331,25 @@ open class MessageGroup: GeneralMessengerCell { } } + open func addMessagesToGroup(_ inserts: [(GeneralMessengerCell, Int)], completion: (() -> Void)?) { + if let insert = inserts.first { + self.updateMessage(insert.0) + } + self.layoutCompletionBlock = completion + + if self.hasLaidOut { + // set state + let indexes = inserts.map { IndexPath(row: $0.1, section: 0) } + self.state = .added(indexes: indexes) + // update table DS + for insert in inserts { + self.messages.insert(insert.0, at: insert.1) + } + // transition avatar + tableview cells + self.transitionLayout(withAnimation: true, shouldMeasureAsync: false, measurementCompletion: nil) + } + } + /** If the message exists in the group, it will be replaced with the new message. **Unimplemented** - parameter message: The message to replace