Skip to content

Commit 8ace150

Browse files
committed
v0.1.0
1 parent cde7249 commit 8ace150

File tree

185 files changed

+19482
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+19482
-177
lines changed

ActionCableClient.podspec

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
#
2-
# Be sure to run `pod lib lint ActionCableClient.podspec' to ensure this is a
3-
# valid spec before submitting.
4-
#
5-
# Any lines starting with a # are optional, but their use is encouraged
6-
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
7-
#
8-
91
Pod::Spec.new do |s|
102
s.name = "ActionCableClient"
113
s.version = "0.1.0"
12-
s.summary = "A short description of ActionCableClient."
13-
14-
# This description is used to generate tags and improve search results.
15-
# * Think: What does it do? Why did you write it? What is the focus?
16-
# * Try to keep it short, snappy and to the point.
17-
# * Write the description between the DESC delimiters below.
18-
# * Finally, don't worry about the indent, CocoaPods strips it!
4+
s.summary = "A Swift client for the Rails ActionCable WebSocket server."
195
s.description = <<-DESC
6+
ActionCable is a new WebSocket server being released with Rails 5 which makes it easy to add real-time features to your app. This Swift client makes it dead-simple to connect with that server, abstracting away everything except what you need to get going.
207
DESC
218

22-
s.homepage = "https://github.com/<GITHUB_USERNAME>/ActionCableClient"
23-
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
9+
s.homepage = "https://github.com/danielrhodes/Swift-ActionCableClient"
2410
s.license = 'MIT'
2511
s.author = { "Daniel Rhodes" => "[email protected]" }
26-
s.source = { :git => "https://github.com/<GITHUB_USERNAME>/ActionCableClient.git", :tag => s.version.to_s }
27-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
12+
s.source = { :git => "https://github.com/danielrhodes/Swift-ActionCableClient.git", :tag => s.version.to_s }
13+
s.social_media_url = 'https://twitter.com/danielrhodes'
2814

2915
s.platform = :ios, '8.0'
3016
s.requires_arc = true
@@ -34,7 +20,7 @@ Pod::Spec.new do |s|
3420
'ActionCableClient' => ['Pod/Assets/*.png']
3521
}
3622

37-
# s.public_header_files = 'Pod/Classes/**/*.h'
38-
# s.frameworks = 'UIKit', 'MapKit'
39-
# s.dependency 'AFNetworking', '~> 2.3'
40-
end
23+
s.frameworks = 'Foundation'
24+
s.dependency 'Starscream', '~> 1.1.2'
25+
s.dependency 'SwiftyJSON', '~> 2.3.1'
26+
end

Example/ActionCableClient.xcodeproj/project.pbxproj

Lines changed: 177 additions & 33 deletions
Large diffs are not rendered by default.

Example/ActionCableClient.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/ActionCableClient/AppDelegate.swift

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
//
2-
// AppDelegate.swift
3-
// ActionCableClient
2+
// Copyright (c) 2016 Daniel Rhodes <[email protected]>
43
//
5-
// Created by Daniel Rhodes on 02/26/2016.
6-
// Copyright (c) 2016 Daniel Rhodes. All rights reserved.
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
721
//
822

923
import UIKit
24+
import ActionCableClient
1025

1126
@UIApplicationMain
1227
class AppDelegate: UIResponder, UIApplicationDelegate {
1328

1429
var window: UIWindow?
15-
16-
30+
1731
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18-
// Override point for customization after application launch.
32+
33+
let controller = ChatViewController()
34+
let navigationController = UINavigationController()
35+
navigationController.pushViewController(controller, animated: false)
36+
self.window = UIWindow();
37+
self.window?.rootViewController = navigationController;
38+
self.window?.makeKeyAndVisible();
39+
1940
return true
2041
}
2142

Example/ActionCableClient/Base.lproj/LaunchScreen.xib

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
56
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
67
</dependencies>
78
<objects>
@@ -11,7 +12,7 @@
1112
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
1213
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1314
<subviews>
14-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
15+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="© 2016 Daniel Rhodes. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
1516
<rect key="frame" x="20" y="439" width="441" height="21"/>
1617
<fontDescription key="fontDescription" type="system" pointSize="17"/>
1718
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>

Example/ActionCableClient/Base.lproj/Main.storyboard

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Copyright (c) 2016 Daniel Rhodes <[email protected]>
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
//
22+
23+
import UIKit
24+
25+
class ChatCell: UITableViewCell {
26+
27+
static var Inset:CGFloat = 20.0
28+
29+
let textView = UILabel()
30+
31+
var message: ChatMessage? {
32+
didSet {
33+
self.textView.attributedText = message?.attributedString()
34+
self.textView.sizeToFit()
35+
}
36+
}
37+
38+
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
39+
super.init(style: style, reuseIdentifier: reuseIdentifier)
40+
textView.frame = CGRectZero
41+
textView.lineBreakMode = NSLineBreakMode.ByWordWrapping
42+
textView.numberOfLines = 0
43+
44+
self.addSubview(textView)
45+
46+
self.layoutMargins = UIEdgeInsetsZero
47+
}
48+
49+
required init?(coder aDecoder: NSCoder) {
50+
fatalError("init(coder:) has not been implemented")
51+
}
52+
53+
override func layoutSubviews() {
54+
super.layoutSubviews()
55+
textView.frame = CGRectInset(self.bounds, ChatCell.Inset, ChatCell.Inset)
56+
}
57+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// Copyright (c) 2016 Daniel Rhodes <[email protected]>
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
//
22+
import Foundation
23+
import UIKit
24+
import SnapKit
25+
26+
27+
class ChatView : UIView {
28+
29+
var tableView: UITableView
30+
var textField: UITextField
31+
var bottomLayoutConstraint: Constraint? = nil
32+
33+
required override init(frame: CGRect) {
34+
self.tableView = UITableView()
35+
self.textField = UITextField()
36+
37+
super.init(frame: frame)
38+
39+
self.tableView.frame = CGRectZero
40+
self.tableView.contentInset = UIEdgeInsetsMake(0, -5, 0, 0);
41+
self.addSubview(self.tableView)
42+
43+
self.textField.frame = CGRectZero
44+
self.textField.borderStyle = UITextBorderStyle.Bezel
45+
self.textField.returnKeyType = UIReturnKeyType.Send
46+
self.textField.placeholder = "Say something..."
47+
self.addSubview(self.textField)
48+
49+
self.backgroundColor = UIColor.whiteColor()
50+
51+
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShowNotification:", name: UIKeyboardWillShowNotification, object: nil)
52+
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHideNotification:", name: UIKeyboardWillHideNotification, object: nil)
53+
}
54+
55+
deinit {
56+
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
57+
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
58+
}
59+
60+
required init?(coder aDecoder: NSCoder) {
61+
fatalError("init(coder:) has not been implemented")
62+
}
63+
64+
override func updateConstraints() {
65+
super.updateConstraints()
66+
67+
tableView.snp_remakeConstraints { (make) -> Void in
68+
make.top.left.right.equalTo(self)
69+
make.bottom.equalTo(textField.snp_top)
70+
}
71+
72+
textField.snp_remakeConstraints { (make) -> Void in
73+
make.left.right.equalTo(self)
74+
make.top.equalTo(tableView.snp_bottom)
75+
make.height.equalTo(50.0)
76+
self.bottomLayoutConstraint = make.bottom.equalTo(self).constraint
77+
}
78+
}
79+
80+
func requiresConstraintBasedLayout() -> Bool {
81+
return true
82+
}
83+
}
84+
85+
86+
//MARK: Notifications
87+
extension ChatView {
88+
func keyboardWillHideNotification(notification: NSNotification) {
89+
let userInfo = notification.userInfo!
90+
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
91+
let rawAnimationCurve = (notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedIntValue << 16
92+
let animationCurve = UIViewAnimationOptions(rawValue: UInt(rawAnimationCurve))
93+
94+
UIView.animateWithDuration(animationDuration, delay: 0.0, options: [.BeginFromCurrentState, animationCurve], animations: {
95+
self.bottomLayoutConstraint?.updateOffset(0)
96+
self.updateConstraintsIfNeeded()
97+
}, completion: nil)
98+
}
99+
100+
func keyboardWillShowNotification(notification: NSNotification) {
101+
let userInfo = notification.userInfo!
102+
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
103+
let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
104+
let convertedKeyboardEndFrame = self.convertRect(keyboardEndFrame, fromView: self.window)
105+
let rawAnimationCurve = (notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedIntValue << 16
106+
let animationCurve = UIViewAnimationOptions(rawValue: UInt(rawAnimationCurve))
107+
UIView.animateWithDuration(animationDuration, delay: 0.0, options: [.BeginFromCurrentState, animationCurve], animations: {
108+
self.bottomLayoutConstraint?.updateOffset(-convertedKeyboardEndFrame.height)
109+
self.updateConstraintsIfNeeded()
110+
}, completion: nil)
111+
}
112+
}
113+

0 commit comments

Comments
 (0)