Skip to content

Commit f9e5a77

Browse files
committed
Remove InternalCollectionView
1 parent 2e7a54f commit f9e5a77

File tree

1 file changed

+33
-62
lines changed

1 file changed

+33
-62
lines changed

StackScrollView/StackScrollView.swift

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import UIKit
2424

25-
open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
25+
open class StackScrollView: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
2626

2727
private enum LayoutKeys {
2828
static let top = "me.muukii.StackScrollView.top"
@@ -40,51 +40,31 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
4040
return layout
4141
}
4242

43-
private let collectionView: InternalCollectionView
44-
45-
open var contentInset: UIEdgeInsets {
46-
get {
47-
return collectionView.contentInset
48-
}
49-
set {
50-
collectionView.contentInset = newValue
51-
}
52-
}
53-
54-
open var scrollIndicatorInsets: UIEdgeInsets {
55-
get {
56-
return collectionView.scrollIndicatorInsets
57-
}
58-
set {
59-
collectionView.scrollIndicatorInsets = newValue
43+
@available(*, unavailable)
44+
open override var dataSource: UICollectionViewDataSource? {
45+
didSet {
6046
}
6147
}
6248

63-
open var keyboardDismissMode: UIScrollViewKeyboardDismissMode {
64-
get {
65-
return collectionView.keyboardDismissMode
66-
}
67-
set {
68-
collectionView.keyboardDismissMode = newValue
49+
@available(*, unavailable)
50+
open override var delegate: UICollectionViewDelegate? {
51+
didSet {
6952
}
7053
}
7154

7255
// MARK: - Initializers
7356

74-
public init(frame: CGRect, collectionViewLayout: UICollectionViewFlowLayout) {
75-
collectionView = InternalCollectionView(frame: frame, collectionViewLayout: collectionViewLayout)
76-
super.init(frame: frame)
57+
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
58+
super.init(frame: frame, collectionViewLayout: layout)
7759
setup()
7860
}
7961

80-
public override init(frame: CGRect) {
81-
collectionView = InternalCollectionView(frame: frame, collectionViewLayout: StackScrollView.defaultLayout())
82-
super.init(frame: frame)
62+
public convenience init(frame: CGRect) {
63+
self.init(frame: frame, collectionViewLayout: StackScrollView.defaultLayout())
8364
setup()
8465
}
8566

8667
public required init?(coder aDecoder: NSCoder) {
87-
collectionView = InternalCollectionView(frame: .zero, collectionViewLayout: StackScrollView.defaultLayout())
8868
super.init(coder: aDecoder)
8969
setup()
9070
}
@@ -99,35 +79,33 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
9979

10080
backgroundColor = .white
10181

102-
addSubview(collectionView)
103-
collectionView.frame = bounds
104-
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
105-
106-
collectionView.alwaysBounceVertical = true
107-
collectionView.delaysContentTouches = false
108-
collectionView.keyboardDismissMode = .interactive
109-
collectionView.backgroundColor = .clear
82+
alwaysBounceVertical = true
83+
delaysContentTouches = false
84+
keyboardDismissMode = .interactive
85+
backgroundColor = .clear
11086

111-
collectionView.delegate = self
112-
collectionView.dataSource = self
87+
super.delegate = self
88+
super.dataSource = self
89+
}
90+
91+
open override func touchesShouldCancel(in view: UIView) -> Bool {
92+
return true
11393
}
11494

11595
open func append(view: UIView) {
11696

11797
views.append(view)
118-
119-
collectionView.register(Cell.self, forCellWithReuseIdentifier: identifier(view))
120-
121-
collectionView.reloadData()
98+
register(Cell.self, forCellWithReuseIdentifier: identifier(view))
99+
reloadData()
122100
}
123101

124102
open func append(views _views: [UIView]) {
125103

126104
views += _views
127105
_views.forEach { view in
128-
collectionView.register(Cell.self, forCellWithReuseIdentifier: identifier(view))
106+
register(Cell.self, forCellWithReuseIdentifier: identifier(view))
129107
}
130-
collectionView.reloadData()
108+
reloadData()
131109
}
132110

133111
// TODO:
@@ -153,17 +131,17 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
153131
.overrideInheritedDuration
154132
],
155133
animations: {
156-
self.collectionView.performBatchUpdates({
157-
self.collectionView.deleteItems(at: [IndexPath.init(item: index, section: 0)])
134+
self.performBatchUpdates({
135+
self.deleteItems(at: [IndexPath(item: index, section: 0)])
158136
}, completion: nil)
159137
}) { (finish) in
160138

161139
}
162140

163141
} else {
164142
UIView.performWithoutAnimation {
165-
collectionView.performBatchUpdates({
166-
self.collectionView.deleteItems(at: [IndexPath.init(item: index, section: 0)])
143+
performBatchUpdates({
144+
self.deleteItems(at: [IndexPath(item: index, section: 0)])
167145
}, completion: nil)
168146
}
169147
}
@@ -173,12 +151,12 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
173151
open func scroll(to view: UIView, animated: Bool) {
174152

175153
let targetRect = view.convert(view.bounds, to: self)
176-
collectionView.scrollRectToVisible(targetRect, animated: true)
154+
scrollRectToVisible(targetRect, animated: true)
177155
}
178156

179157
open func scroll(to view: UIView, at position: UICollectionViewScrollPosition, animated: Bool) {
180158
if let index = views.index(of: view) {
181-
collectionView.scrollToItem(at: IndexPath(item: index, section: 0), at: position, animated: animated)
159+
scrollToItem(at: IndexPath(item: index, section: 0), at: position, animated: animated)
182160
}
183161
}
184162

@@ -269,14 +247,14 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
269247
.overrideInheritedDuration
270248
],
271249
animations: {
272-
self.collectionView.performBatchUpdates(nil, completion: nil)
250+
self.performBatchUpdates(nil, completion: nil)
273251
self.layoutIfNeeded()
274252
}) { (finish) in
275253

276254
}
277255
} else {
278256
UIView.performWithoutAnimation {
279-
self.collectionView.performBatchUpdates(nil, completion: nil)
257+
self.performBatchUpdates(nil, completion: nil)
280258
self.layoutIfNeeded()
281259
}
282260
}
@@ -289,10 +267,3 @@ open class StackScrollView: UIView, UICollectionViewDataSource, UICollectionView
289267
}
290268
}
291269
}
292-
293-
private class InternalCollectionView: UICollectionView {
294-
295-
open override func touchesShouldCancel(in view: UIView) -> Bool {
296-
return true
297-
}
298-
}

0 commit comments

Comments
 (0)