-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppDelegate.swift
163 lines (117 loc) · 5.14 KB
/
AppDelegate.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
// AppDelegate.swift
// CenteredCell
//
// Created by Prashant on 15/04/19.
// Copyright © 2019 Prashant. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let callManager = CallManager()
var providerDelegate:ProviderDelegate!
class var shared: AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
providerDelegate = ProviderDelegate(callManager: callManager)
self.window?.rootViewController = RootVC()
self.window?.makeKeyAndVisible()
return true
}
func displayIncomingCall(uuid:UUID,handle:String,hasVideo:Bool,completion:((Error?) -> ())?) {
providerDelegate.reportIncomingCall(uuid: uuid, handle: handle, hasVideo: hasVideo, completion: completion)
}
}
class WLCollectionCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
func setup() {
self.layer.borderWidth = 1.0
self.layer.borderColor = UIColor.red.cgColor
self.layer.cornerRadius = 5.0
self.backgroundColor = UIColor.white
}
}
class WLCollectionViewLayout: UICollectionViewFlowLayout {
var previousOffset: CGFloat = 0
var currentPage: Int = 0
override func prepare() {
}
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
guard let collectionView = self.collectionView else {
return CGPoint.zero
}
guard let itemsCount = collectionView.dataSource?.collectionView(collectionView, numberOfItemsInSection: 0) else {
return CGPoint.zero
}
if ((previousOffset > collectionView.contentOffset.x) && (velocity.x < 0)) {
currentPage = max(currentPage - 1, 0)
} else if ((previousOffset < collectionView.contentOffset.x) && (velocity.x > 0.0)) {
currentPage = min(currentPage + 1, itemsCount - 1);
}
let itemEdgeOffset:CGFloat = (collectionView.frame.width - itemSize.width - minimumLineSpacing * 2) / 2
let updatedOffset: CGFloat = (itemSize.width + minimumLineSpacing) * CGFloat(currentPage) - (itemEdgeOffset + minimumLineSpacing);
previousOffset = updatedOffset;
return CGPoint(x: updatedOffset, y: proposedContentOffset.y);
}
}
class RootVC: UIViewController, UICollectionViewDataSource {
var collectionView: UICollectionView?
var collectionLayout: WLCollectionViewLayout = WLCollectionViewLayout()
override func viewDidLoad() {
super.viewDidLoad()
/*
*
|<------- view width -------->|
---------------------------------------
| |
|<-w0->|<ws>|<-- wi -->|<ws>|<-w0->|
--------------- --------------- ---------------
| | | | | |
| | | | | |
--------------- --------------- ---------------
| |
| |
---------------------------------------
*
* w0: itemEdgeOffset
* ws: space
* wi: itemWidth
* in this example: ws == w0
*/
let space: CGFloat = 30
self.view = UIView(frame: UIScreen.main.bounds)
self.view.backgroundColor = UIColor.blue
let collectionFrame = CGRect(x: 0, y: 60, width: view.frame.width, height: view.frame.height - 120)
self.collectionView = UICollectionView(frame: collectionFrame, collectionViewLayout: collectionLayout)
collectionView?.register(WLCollectionCell.self, forCellWithReuseIdentifier: "CELL")
collectionView?.backgroundColor = self.view.backgroundColor
collectionView?.dataSource = self
collectionView?.isPagingEnabled = false
collectionView?.contentInset = UIEdgeInsets(top: 0, left: space, bottom: 0, right: space)
collectionLayout.scrollDirection = .horizontal
let itemWidth = view.frame.width - space * 4 // w0 == ws
collectionLayout.itemSize = CGSize(width: itemWidth, height: view.frame.height - 120 - 40)
collectionLayout.minimumLineSpacing = space
self.view.addSubview(self.collectionView!)
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell: WLCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CELL", for: indexPath) as? WLCollectionCell {
return cell
}
return UICollectionViewCell()
}
}