forked from xmartlabs/XLActionController
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweetbot.swift
99 lines (86 loc) · 4.36 KB
/
Tweetbot.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Tweetbot.swift
// Tweetbot ( https://github.com/xmartlabs/XLActionController )
//
// Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Foundation
#if XLACTIONCONTROLLER_EXAMPLE
import XLActionController
#endif
public class TweetbotCell: ActionCell {
public override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public override func awakeFromNib() {
super.awakeFromNib()
initialize()
}
func initialize() {
actionTitleLabel?.font = UIFont(name: "HelveticaNeue-Bold", size: 18)
actionTitleLabel?.textColor = .whiteColor()
actionTitleLabel?.textAlignment = .Center
backgroundColor = .darkGrayColor()
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor(red: 0.31, green: 0.42, blue: 0.54, alpha: 1.0)
selectedBackgroundView = backgroundView
}
}
public class TweetbotActionController: DynamicsActionController<TweetbotCell, String, UICollectionReusableView, Void, UICollectionReusableView, Void> {
public override init(nibName nibNameOrNil: String? = nil, bundle nibBundleOrNil: NSBundle? = nil) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
backgroundView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
settings.animation.present.duration = 0.5
settings.animation.dismiss.duration = 0.5
settings.behavior.bounces = true
settings.behavior.useDynamics = true
collectionView.contentInset = UIEdgeInsets(top: 0.0, left: 12.0, bottom: 6.0, right: 12.0)
(collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.sectionInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 6.0, right: 0.0)
cellSpec = .NibFile(nibName: "TweetbotCell", bundle: NSBundle(forClass: TweetbotCell.self), height: { _ in 50 })
onConfigureCellForAction = { [weak self] cell, action, indexPath in
cell.setup(action.data, detail: nil, image: nil)
let actions = self?.sectionForIndex(indexPath.section)?.actions
let actionsCount = actions!.count
cell.separatorView?.hidden = indexPath.item == (self?.collectionView.numberOfItemsInSection(indexPath.section))! - 1
cell.backgroundColor = action.style == .Cancel ? UIColor(white: 0.23, alpha: 1.0) : .darkGrayColor()
cell.alpha = action.enabled ? 1.0 : 0.5
var corners = UIRectCorner()
if indexPath.item == 0 {
corners = UIRectCorner.TopLeft.union(.TopRight)
}
if indexPath.item == actionsCount - 1 {
corners = corners.union(.BottomLeft).union(.BottomRight)
}
if corners == UIRectCorner.AllCorners {
cell.layer.mask = nil
cell.layer.cornerRadius = 8.0
} else {
let borderMask = CAShapeLayer()
borderMask.frame = cell.bounds
borderMask.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: 8.0, height: 8.0)).CGPath
cell.layer.mask = borderMask
}
}
}
}