@@ -18,18 +18,76 @@ open class ASCollectionSectionedDataSource<S: SectionModelType>: NSObject, ASCol
18
18
public typealias Section = S
19
19
20
20
public typealias ConfigureCell = ( ASCollectionSectionedDataSource < S > , ASCollectionNode , IndexPath , I ) -> ASCellNode
21
+ public typealias ConfigureCellBlock = ( ASCollectionSectionedDataSource < S > , ASCollectionNode , IndexPath , I ) -> ASCellNodeBlock
21
22
public typealias ConfigureSupplementaryView = ( ASCollectionSectionedDataSource < S > , ASCollectionNode , String , IndexPath ) -> ASCellNode
23
+ public typealias ConfigureSupplementaryViewBlock = ( ASCollectionSectionedDataSource < S > , ASCollectionNode , String , IndexPath ) -> ASCellNodeBlock
22
24
public typealias MoveItem = ( ASCollectionSectionedDataSource < S > , _ sourceIndexPath: IndexPath , _ destinationIndexPath: IndexPath ) -> Void
23
25
public typealias CanMoveItemAtIndexPath = ( ASCollectionSectionedDataSource < S > , IndexPath ) -> Bool
24
26
27
+ fileprivate static func configureCellNotSet( dataSource: ASCollectionSectionedDataSource < S > , node: ASCollectionNode , indexPath: IndexPath , model: I ) -> ASCellNode {
28
+ return ASCollectionDataSourceNotSet ( ) . collectionNode ( node, nodeForItemAt: indexPath)
29
+ }
30
+
31
+ fileprivate static func configureCellBlockNotSet( dataSource: ASCollectionSectionedDataSource < S > , node: ASCollectionNode , indexPath: IndexPath , model: I ) -> ASCellNodeBlock {
32
+ return { dataSource. collectionNode ( node, nodeForItemAt: indexPath) }
33
+ }
34
+
35
+ fileprivate static func configureSupplementaryViewBlockNotSet( dataSource: ASCollectionSectionedDataSource < S > , node: ASCollectionNode , nodeForSupplementaryElementOfKind kind: String , indexPath: IndexPath ) -> ASCellNodeBlock {
36
+ return { dataSource. collectionNode ( node, nodeForSupplementaryElementOfKind: kind, at: indexPath) }
37
+ }
38
+
25
39
public init (
26
40
configureCell: @escaping ConfigureCell ,
27
41
configureSupplementaryView: ConfigureSupplementaryView ? = nil ,
28
42
moveItem: @escaping MoveItem = { _, _, _ in ( ) } ,
29
43
canMoveItemAtIndexPath: @escaping CanMoveItemAtIndexPath = { _, _ in false }
30
44
) {
31
45
self . configureCell = configureCell
46
+ self . configureCellBlock = ASCollectionSectionedDataSource . configureCellBlockNotSet
47
+ self . configureSupplementaryView = configureSupplementaryView
48
+ self . configureSupplementaryViewBlock = ASCollectionSectionedDataSource . configureSupplementaryViewBlockNotSet
49
+ self . moveItem = moveItem
50
+ self . canMoveItemAtIndexPath = canMoveItemAtIndexPath
51
+ }
52
+
53
+ public init (
54
+ configureCellBlock: @escaping ConfigureCellBlock ,
55
+ configureSupplementaryView: ConfigureSupplementaryView ? = nil ,
56
+ moveItem: @escaping MoveItem = { _, _, _ in ( ) } ,
57
+ canMoveItemAtIndexPath: @escaping CanMoveItemAtIndexPath = { _, _ in false }
58
+ ) {
59
+ self . configureCell = ASCollectionSectionedDataSource . configureCellNotSet
60
+ self . configureCellBlock = configureCellBlock
32
61
self . configureSupplementaryView = configureSupplementaryView
62
+ self . configureSupplementaryViewBlock = ASCollectionSectionedDataSource . configureSupplementaryViewBlockNotSet
63
+ self . moveItem = moveItem
64
+ self . canMoveItemAtIndexPath = canMoveItemAtIndexPath
65
+ }
66
+
67
+ public init (
68
+ configureCell: @escaping ConfigureCell ,
69
+ configureSupplementaryViewBlock: ConfigureSupplementaryViewBlock ? = nil ,
70
+ moveItem: @escaping MoveItem = { _, _, _ in ( ) } ,
71
+ canMoveItemAtIndexPath: @escaping CanMoveItemAtIndexPath = { _, _ in false }
72
+ ) {
73
+ self . configureCell = configureCell
74
+ self . configureCellBlock = ASCollectionSectionedDataSource . configureCellBlockNotSet
75
+ self . configureSupplementaryView = nil
76
+ self . configureSupplementaryViewBlock = configureSupplementaryViewBlock
77
+ self . moveItem = moveItem
78
+ self . canMoveItemAtIndexPath = canMoveItemAtIndexPath
79
+ }
80
+
81
+ public init (
82
+ configureCellBlock: @escaping ConfigureCellBlock ,
83
+ configureSupplementaryViewBlock: ConfigureSupplementaryViewBlock ? = nil ,
84
+ moveItem: @escaping MoveItem = { _, _, _ in ( ) } ,
85
+ canMoveItemAtIndexPath: @escaping CanMoveItemAtIndexPath = { _, _ in false }
86
+ ) {
87
+ self . configureCell = ASCollectionSectionedDataSource . configureCellNotSet
88
+ self . configureCellBlock = configureCellBlock
89
+ self . configureSupplementaryView = nil
90
+ self . configureSupplementaryViewBlock = configureSupplementaryViewBlock
33
91
self . moveItem = moveItem
34
92
self . canMoveItemAtIndexPath = canMoveItemAtIndexPath
35
93
}
@@ -92,10 +150,34 @@ open class ASCollectionSectionedDataSource<S: SectionModelType>: NSObject, ASCol
92
150
}
93
151
}
94
152
153
+ open var configureCellBlock : ConfigureCellBlock {
154
+ didSet {
155
+ #if DEBUG
156
+ ensureNotMutatedAfterBinding ( )
157
+ #endif
158
+ }
159
+ }
160
+
95
161
open var configureSupplementaryView : ConfigureSupplementaryView ? {
96
162
didSet {
97
163
#if DEBUG
98
164
ensureNotMutatedAfterBinding ( )
165
+
166
+ if self . configureSupplementaryViewBlock != nil {
167
+ print ( " [WARNING][RxASDataSources] `configureSupplementaryView` is always over written by `configureSupplementaryViewBlock`. " )
168
+ }
169
+ #endif
170
+ }
171
+ }
172
+
173
+ open var configureSupplementaryViewBlock : ConfigureSupplementaryViewBlock ? {
174
+ didSet {
175
+ #if DEBUG
176
+ ensureNotMutatedAfterBinding ( )
177
+
178
+ if self . configureSupplementaryView != nil {
179
+ print ( " [WARNING][RxASDataSources] `configureSupplementaryViewBlock` always over write `configureSupplementaryView`. " )
180
+ }
99
181
#endif
100
182
}
101
183
}
@@ -107,6 +189,7 @@ open class ASCollectionSectionedDataSource<S: SectionModelType>: NSObject, ASCol
107
189
#endif
108
190
}
109
191
}
192
+
110
193
open var canMoveItemAtIndexPath : CanMoveItemAtIndexPath {
111
194
didSet {
112
195
#if DEBUG
@@ -131,13 +214,27 @@ open class ASCollectionSectionedDataSource<S: SectionModelType>: NSObject, ASCol
131
214
return configureCell ( self , collectionNode, indexPath, self [ indexPath] )
132
215
}
133
216
217
+ open func collectionNode( _ collectionNode: ASCollectionNode , nodeBlockForItemAt indexPath: IndexPath ) -> ASCellNodeBlock {
218
+ precondition ( indexPath. item < _sectionModels [ indexPath. section] . items. count)
219
+
220
+ return configureCellBlock ( self , collectionNode, indexPath, self [ indexPath] )
221
+ }
222
+
134
223
open func collectionNode( _ collectionNode: ASCollectionNode , nodeForSupplementaryElementOfKind kind: String , at indexPath: IndexPath ) -> ASCellNode {
135
224
guard let cell = configureSupplementaryView ? ( self , collectionNode, kind, indexPath) else {
136
225
fatalError ( " configureSupplementaryView was not set " )
137
226
}
138
227
return cell
139
228
}
140
229
230
+ open func collectionNode( _ collectionNode: ASCollectionNode , nodeBlockForSupplementaryElementOfKind kind: String , at indexPath: IndexPath ) -> ASCellNodeBlock {
231
+ guard let cell = configureSupplementaryViewBlock ? ( self , collectionNode, kind, indexPath) else {
232
+ fatalError ( " configureSUpplementaryViewBlock was not set " )
233
+ }
234
+
235
+ return cell
236
+ }
237
+
141
238
open func collectionNode( _ collectionNode: ASCollectionNode , canMoveItemAt indexPath: IndexPath ) -> Bool {
142
239
return canMoveItemAtIndexPath ( self , indexPath)
143
240
}
0 commit comments