Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Feat/add messages to groups #118

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NMessenger.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions nMessenger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */; };
Expand Down Expand Up @@ -581,7 +579,6 @@
F1FC87311D63813700F3C21C /* MessageNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageNode.swift; sourceTree = "<group>"; };
F1FC87341D63813700F3C21C /* CameraViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = "<group>"; };
F1FC87361D63813700F3C21C /* NMessengerBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessengerBarView.swift; sourceTree = "<group>"; };
F1FC87371D63813700F3C21C /* NMessengerBarView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NMessengerBarView.xib; sourceTree = "<group>"; };
F1FC87381D63813700F3C21C /* NMessenger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessenger.swift; sourceTree = "<group>"; };
F1FC87391D63813700F3C21C /* NMessengerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMessengerViewController.swift; sourceTree = "<group>"; };
F1FC873B1D63813700F3C21C /* ModalAlertUtilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalAlertUtilities.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1101,7 +1098,6 @@
F13F39E01D650D490021A858 /* InputBarViewProtocol.swift */,
F14C8B681D66273700F8616F /* InputBarView.swift */,
F1FC87361D63813700F3C21C /* NMessengerBarView.swift */,
F1FC87371D63813700F3C21C /* NMessengerBarView.xib */,
);
path = InputBarView;
sourceTree = "<group>";
Expand Down Expand Up @@ -1399,7 +1395,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 */,
);
Expand Down Expand Up @@ -1427,7 +1422,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 */,
Expand Down
6 changes: 3 additions & 3 deletions nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nMessenger/Source/MessageNodes/Bubbles/StackedBubble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
128 changes: 109 additions & 19 deletions nMessenger/Source/MessageNodes/MessageCell/MessageGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ 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
}

/** 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*/
Expand All @@ -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
Expand Down Expand Up @@ -179,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!)
}
Expand All @@ -206,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
})
}
Expand Down Expand Up @@ -289,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
Expand All @@ -299,6 +307,49 @@ 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(indexes: [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)
}
}

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
Expand Down Expand Up @@ -394,23 +445,62 @@ open class MessageGroup: GeneralMessengerCell {
fileprivate func updateMessage(_ message: GeneralMessengerCell) {
message.currentTableNode = self.messageTable

//message specific UI
if messages.first == nil { //will be the first message
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
switch primaryBubblePosition {
case .first:
//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
}
}
} 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:
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 {
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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading