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

Commit

Permalink
Migrated to Swift 3 and ASDK 1.9.90
Browse files Browse the repository at this point in the history
Changes according to @atainter comments
  • Loading branch information
DavidSchechter committed Sep 14, 2016
1 parent 0a3f9f7 commit 8f8733e
Show file tree
Hide file tree
Showing 42 changed files with 1,266 additions and 964 deletions.
4 changes: 2 additions & 2 deletions 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.76"
s.version = "1.0.77"
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 @@ -133,5 +133,5 @@ NMessenger is a fast, lightweight messenger component built on AsyncDisplaykit a
s.requires_arc = true

# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency "AsyncDisplayKit", "1.9.80"
s.dependency "AsyncDisplayKit", "1.9.90"
end
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target 'nMessenger' do
use_frameworks!

# Pods for nMessenger
pod 'AsyncDisplayKit', '1.9.80'
pod 'AsyncDisplayKit', 1.9.90'
target 'nMessengerTests' do
inherit! :search_paths
Expand Down
201 changes: 200 additions & 1 deletion nMessenger.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions nMessenger/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
20 changes: 20 additions & 0 deletions nMessenger/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
5 changes: 5 additions & 0 deletions nMessenger/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) wants acceess to Photos</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) wants acceess to Camera</string>

</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ import Foundation
import UIKit

/** Uses a simple bubble as primary and a simple bubble as secondary. Incoming color is pale grey and outgoing is mid grey */
public class ImageBubbleConfiguration: BubbleConfigurationProtocol {
open class ImageBubbleConfiguration: BubbleConfigurationProtocol {

public var isMasked = false
open var isMasked = false

public init() {}

public func getIncomingColor() -> UIColor
open func getIncomingColor() -> UIColor
{
return UIColor.n1PaleGreyColor()
}

public func getOutgoingColor() -> UIColor
open func getOutgoingColor() -> UIColor
{
return UIColor.n1ActionBlueColor()
}

public func getBubble() -> Bubble
open func getBubble() -> Bubble
{
let newBubble = ImageBubble()
newBubble.bubbleImage = UIImage(named: "MessageBubble", inBundle: NSBundle(forClass: NMessengerViewController.self), compatibleWithTraitCollection: nil)
newBubble.bubbleImage = UIImage(named: "MessageBubble", in: Bundle(for: NMessengerViewController.self), compatibleWith: nil)
newBubble.cutInsets = UIEdgeInsetsMake(29, 32, 25, 43)
newBubble.hasLayerMask = isMasked
return newBubble
}

public func getSecondaryBubble() -> Bubble
open func getSecondaryBubble() -> Bubble
{
let newBubble = ImageBubble()
newBubble.bubbleImage = UIImage(named: "MessageBubble", inBundle: NSBundle(forClass: NMessengerViewController.self), compatibleWithTraitCollection: nil)
newBubble.bubbleImage = UIImage(named: "MessageBubble", in: Bundle(for: NMessengerViewController.self), compatibleWith: nil)
newBubble.cutInsets = UIEdgeInsetsMake(29, 32, 25, 43)
newBubble.hasLayerMask = isMasked
return newBubble
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ import Foundation
import UIKit

/** Uses a simple bubble as primary and a simple bubble as secondary. Incoming color is pale grey and outgoing is mid grey */
public class SimpleBubbleConfiguration: BubbleConfigurationProtocol {
open class SimpleBubbleConfiguration: BubbleConfigurationProtocol {

public var isMasked = false
open var isMasked = false

public init() {}

public func getIncomingColor() -> UIColor
open func getIncomingColor() -> UIColor
{
return UIColor.n1PaleGreyColor()
}

public func getOutgoingColor() -> UIColor
open func getOutgoingColor() -> UIColor
{
return UIColor.n1MidGreyColor()
}

public func getBubble() -> Bubble
open func getBubble() -> Bubble
{
let newBubble = SimpleBubble()
newBubble.hasLayerMask = isMasked
return newBubble
}

public func getSecondaryBubble() -> Bubble
open func getSecondaryBubble() -> Bubble
{
let newBubble = SimpleBubble()
newBubble.hasLayerMask = isMasked
return newBubble
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ import Foundation
import UIKit

/** Uses a default bubble as primary and a stacked bubble as secondary. Incoming color is pale grey and outgoing is blue */
public class StandardBubbleConfiguration: BubbleConfigurationProtocol {
open class StandardBubbleConfiguration: BubbleConfigurationProtocol {

public var isMasked = false
open var isMasked = false

public init() {}

public func getIncomingColor() -> UIColor
open func getIncomingColor() -> UIColor
{
return UIColor.n1PaleGreyColor()
}

public func getOutgoingColor() -> UIColor
open func getOutgoingColor() -> UIColor
{
return UIColor.n1ActionBlueColor()
}

public func getBubble() -> Bubble
open func getBubble() -> Bubble
{
let newBubble = DefaultBubble()
newBubble.hasLayerMask = isMasked
return newBubble
}

public func getSecondaryBubble() -> Bubble
open func getSecondaryBubble() -> Bubble
{
let newBubble = StackedBubble()
newBubble.hasLayerMask = isMasked
return newBubble
}
}
}
22 changes: 11 additions & 11 deletions nMessenger/Source/MessageNodes/Bubbles/Bubble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ import AsyncDisplayKit
/**
'Abstract' Bubble class. Subclass for creating a custom bubble
*/
public class Bubble {
open class Bubble {

// MARK: Public Parameters
public var bubbleColor : UIColor = UIColor.n1PaleGreyColor()
open var bubbleColor : UIColor = UIColor.n1PaleGreyColor()

/** When this is set, the layer mask will mask the ContentNode.*/
public var hasLayerMask = false
open var hasLayerMask = false

/**
A layer for the bubble. Make sure this property is first accessed on the main thread.
*/
public lazy var layer: CAShapeLayer = CAShapeLayer()
open lazy var layer: CAShapeLayer = CAShapeLayer()
/**
A layer that holds a mask which is the same shape as the bubble. This can be used to mask anything in the ContentNode to the same shape as the bubble.
*/
public lazy var maskLayer: CAShapeLayer = CAShapeLayer()
open lazy var maskLayer: CAShapeLayer = CAShapeLayer()

/** Bounds of the bubble*/
public var calculatedBounds = CGRectZero
open var calculatedBounds = CGRect.zero

// MARK: Initialisers
public init() {}
Expand All @@ -44,20 +44,20 @@ public class Bubble {
Sizes the layer accordingly. This function should **always** be thread safe.
-parameter bounds: The bounds of the content
*/
public func sizeToBounds(bounds: CGRect) {
open func sizeToBounds(_ bounds: CGRect) {
self.calculatedBounds = bounds
}


/**
This function should be called on the main thread. It makes creates the layer with the calculated values from *sizeToBounds*
*/
public func createLayer() {
open func createLayer() {
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.mainScreen().scale
self.layer.rasterizationScale = UIScreen.main.scale

self.maskLayer.shouldRasterize = true
self.maskLayer.rasterizationScale = UIScreen.mainScreen().scale
self.maskLayer.rasterizationScale = UIScreen.main.scale
}

}
}
47 changes: 26 additions & 21 deletions nMessenger/Source/MessageNodes/Bubbles/DefaultBubble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import UIKit
/**
Default bubble class is standard with our message configuration. It has three rounded corners and one square corner closest to the avatar.
*/
public class DefaultBubble: Bubble {
open class DefaultBubble: Bubble {

//MARK: Public Variables

/** Radius of the corners for the bubble. When this is set, you will need to call setNeedsLayout on your message for changes to take effect if the bubble has already been drawn*/
public var radius : CGFloat = 16
open var radius : CGFloat = 16
/** Should be less or equal to the *radius* property. When this is set, you will need to call setNeedsLayout on your message for changes to take effect if the bubble has already been drawn*/
public var borderWidth : CGFloat = 0 //TODO:
open var borderWidth : CGFloat = 0 //TODO:
/** The color of the border around the bubble. When this is set, you will need to call setNeedsLayout on your message for changes to take effect if the bubble has already been drawn*/
public var bubbleBorderColor : UIColor = UIColor.clearColor()
open var bubbleBorderColor : UIColor = UIColor.clear
/** Path used to cutout the bubble*/
public private(set) var path: CGMutablePath = CGPathCreateMutable()
open fileprivate(set) var path: CGMutablePath = CGMutablePath()

// MARK: Initialisers

Expand All @@ -43,10 +43,10 @@ public class DefaultBubble: Bubble {
Overriding sizeToBounds from super class
-parameter bounds: The bounds of the content
*/
public override func sizeToBounds(bounds: CGRect) {
open override func sizeToBounds(_ bounds: CGRect) {
super.sizeToBounds(bounds)

var rect = CGRectZero
var rect = CGRect.zero
var radius2: CGFloat = 0

if bounds.width < 2*radius || bounds.height < 2*radius { //if the rect calculation yeilds a negative result
Expand All @@ -55,40 +55,45 @@ public class DefaultBubble: Bubble {

let newRadius = newRadiusW>newRadiusH ? newRadiusH : newRadiusW

rect = CGRectMake(newRadius, newRadius, bounds.width - 2*newRadius, bounds.height - 2*newRadius)
rect = CGRect(x: newRadius, y: newRadius, width: bounds.width - 2*newRadius, height: bounds.height - 2*newRadius)
radius2 = newRadius - borderWidth / 2
} else {
rect = CGRectMake(radius, radius, bounds.width - 2*radius, bounds.height - 2*radius)
rect = CGRect(x: radius, y: radius, width: bounds.width - 2*radius, height: bounds.height - 2*radius)
radius2 = radius - borderWidth / 2
}

path = CGPathCreateMutable()

CGPathAddArc(path, nil, rect.maxX, rect.minY, radius2, CGFloat(-M_PI_2), 0, false)
CGPathAddLineToPoint(path, nil, rect.maxX + radius2, rect.maxY + radius2)
CGPathAddArc(path, nil, rect.minX, rect.maxY, radius2, CGFloat(M_PI_2), CGFloat(M_PI), false)
CGPathAddArc(path, nil, rect.minX, rect.minY, radius2, CGFloat(M_PI), CGFloat(-M_PI_2), false)
CGPathCloseSubpath(path)
path = CGMutablePath()

path.addArc(center: CGPoint(x: rect.maxX, y: rect.minY), radius: radius2, startAngle: CGFloat(-M_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)

//CGPathAddArc(path, nil, rect.maxX, rect.minY, radius2, CGFloat(-M_PI_2), 0, false)
//CGPathAddLineToPoint(path, nil, rect.maxX + radius2, rect.maxY + radius2)
//CGPathAddArc(path, nil, rect.minX, rect.maxY, radius2, CGFloat(M_PI_2), CGFloat(M_PI), false)
//CGPathAddArc(path, nil, rect.minX, rect.minY, radius2, CGFloat(M_PI), CGFloat(-M_PI_2), false)
path.closeSubpath()
}

/**
Overriding createLayer from super class
*/
public override func createLayer() {
open override func createLayer() {
super.createLayer()

CATransaction.begin()
CATransaction.setDisableActions(true)
self.layer.path = path
self.layer.fillColor = self.bubbleColor.CGColor
self.layer.strokeColor = self.bubbleBorderColor.CGColor
self.layer.fillColor = self.bubbleColor.cgColor
self.layer.strokeColor = self.bubbleBorderColor.cgColor
self.layer.lineWidth = self.borderWidth
self.layer.position = CGPoint.zero

self.maskLayer.fillColor = UIColor.blackColor().CGColor
self.maskLayer.fillColor = UIColor.black.cgColor
self.maskLayer.path = path
self.maskLayer.position = CGPoint.zero
CATransaction.commit()

}
}
}
Loading

0 comments on commit 8f8733e

Please sign in to comment.