@@ -103,42 +103,39 @@ + (NSUInteger)parallelProcessorCount
103
103
104
104
#pragma mark - Cell Layout
105
105
106
- - (void )_layoutNode : (ASCellNode *)node withConstrainedSize : (ASSizeRange) constrainedSize
106
+ - (void )batchLayoutNodes : ( NSArray *)nodes ofKind : ( NSString *) kind atIndexPaths : ( NSArray *) indexPaths completion : ( void (^)( NSArray *nodes, NSArray *indexPaths)) completionBlock
107
107
{
108
- [node measureWithSizeRange: constrainedSize];
109
- node.frame = CGRectMake (0 .0f , 0 .0f , node.calculatedSize .width , node.calculatedSize .height );
108
+ NSUInteger blockSize = [[ASDataController class ] parallelProcessorCount ] * kASDataControllerSizingCountPerProcessor ;
109
+
110
+ // Processing in batches
111
+ for (NSUInteger i = 0 ; i < indexPaths.count ; i += blockSize) {
112
+ NSRange batchedRange = NSMakeRange (i, MIN (indexPaths.count - i, blockSize));
113
+ NSArray *batchedIndexPaths = [indexPaths subarrayWithRange: batchedRange];
114
+ NSArray *batchedNodes = [nodes subarrayWithRange: batchedRange];
115
+
116
+ [self _layoutNodes: batchedNodes ofKind: kind atIndexPaths: batchedIndexPaths completion: completionBlock];
117
+ }
110
118
}
111
119
112
- /*
113
- * Perform measurement and layout of loaded nodes on the main thread, skipping unloaded nodes.
114
- *
115
- * @discussion Once nodes have loaded their views, we can't layout in the background so this is a chance
116
- * to do so immediately on the main thread.
117
- */
118
- - (void )_layoutNodesWithMainThreadAffinity : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths {
120
+ - (void )layoutLoadedNodes : (NSArray *)nodes ofKind : (NSString *)kind atIndexPaths : (NSArray *)indexPaths {
119
121
NSAssert (NSThread .isMainThread, @" Main thread layout must be on the main thread." );
120
122
121
123
[indexPaths enumerateObjectsUsingBlock: ^(NSIndexPath *indexPath, NSUInteger idx, __unused BOOL * stop) {
122
124
ASCellNode *node = nodes[idx];
123
125
if (node.isNodeLoaded ) {
124
- ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind: ASDataControllerRowNodeKind atIndexPath: indexPath];
126
+ ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind: kind atIndexPath: indexPath];
125
127
[self _layoutNode: node withConstrainedSize: constrainedSize];
126
128
}
127
129
}];
128
130
}
129
131
130
- - (void )batchLayoutNodes : (NSArray *)nodes ofKind : (NSString *)kind atIndexPaths : (NSArray *)indexPaths completion : (void (^)(NSArray *nodes, NSArray *indexPaths))completionBlock
132
+ /* *
133
+ * Measure and layout the given node with the constrained size range.
134
+ */
135
+ - (void )_layoutNode : (ASCellNode *)node withConstrainedSize : (ASSizeRange)constrainedSize
131
136
{
132
- NSUInteger blockSize = [[ASDataController class ] parallelProcessorCount ] * kASDataControllerSizingCountPerProcessor ;
133
-
134
- // Processing in batches
135
- for (NSUInteger i = 0 ; i < indexPaths.count ; i += blockSize) {
136
- NSRange batchedRange = NSMakeRange (i, MIN (indexPaths.count - i, blockSize));
137
- NSArray *batchedIndexPaths = [indexPaths subarrayWithRange: batchedRange];
138
- NSArray *batchedNodes = [nodes subarrayWithRange: batchedRange];
139
-
140
- [self _layoutNodes: batchedNodes ofKind: kind atIndexPaths: batchedIndexPaths completion: completionBlock];
141
- }
137
+ [node measureWithSizeRange: constrainedSize];
138
+ node.frame = CGRectMake (0 .0f , 0 .0f , node.calculatedSize .width , node.calculatedSize .height );
142
139
}
143
140
144
141
/* *
@@ -176,7 +173,7 @@ - (void)_layoutNodes:(NSArray *)nodes ofKind:(NSString *)kind atIndexPaths:(NSAr
176
173
for (NSUInteger k = j; k < j + batchCount; k++) {
177
174
ASCellNode *node = nodes[k];
178
175
// Only measure nodes whose views aren't loaded, since we're in the background.
179
- // We should already have measured loaded nodes before we left the main thread, using _layoutNodesWithMainThreadAffinity :
176
+ // We should already have measured loaded nodes before we left the main thread, using layoutLoadedNodes:ofKind:atIndexPaths :
180
177
if (!node.isNodeLoaded ) {
181
178
[self _layoutNode: node withConstrainedSize: nodeBoundSizes[k]];
182
179
}
@@ -371,7 +368,7 @@ - (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animati
371
368
[self _populateFromEntireDataSourceWithMutableNodes: updatedNodes mutableIndexPaths: updatedIndexPaths];
372
369
373
370
// Measure nodes whose views are loaded before we leave the main thread
374
- [self _layoutNodesWithMainThreadAffinity : updatedNodes atIndexPaths: updatedIndexPaths];
371
+ [self layoutLoadedNodes : updatedNodes ofKind: ASDataControllerRowNodeKind atIndexPaths: updatedIndexPaths];
375
372
376
373
// Allow subclasses to perform setup before going into the edit transaction
377
374
[self prepareForReloadData ];
@@ -550,14 +547,14 @@ - (void)insertSections:(NSIndexSet *)sections withAnimationOptions:(ASDataContro
550
547
[_editingTransactionQueue waitUntilAllOperationsAreFinished ];
551
548
552
549
[self accessDataSourceWithBlock: ^{
553
- [self prepareForInsertSections: sections];
554
-
555
550
NSMutableArray *updatedNodes = [NSMutableArray array ];
556
551
NSMutableArray *updatedIndexPaths = [NSMutableArray array ];
557
552
[self _populateFromDataSourceWithSectionIndexSet: sections mutableNodes: updatedNodes mutableIndexPaths: updatedIndexPaths];
558
553
559
554
// Measure nodes whose views are loaded before we leave the main thread
560
- [self _layoutNodesWithMainThreadAffinity: updatedNodes atIndexPaths: updatedIndexPaths];
555
+ [self layoutLoadedNodes: updatedNodes ofKind: ASDataControllerRowNodeKind atIndexPaths: updatedIndexPaths];
556
+
557
+ [self prepareForInsertSections: sections];
561
558
562
559
[_editingTransactionQueue addOperationWithBlock: ^{
563
560
[self willInsertSections: sections];
@@ -604,8 +601,6 @@ - (void)reloadSections:(NSIndexSet *)sections withAnimationOptions:(ASDataContro
604
601
[_editingTransactionQueue waitUntilAllOperationsAreFinished ];
605
602
606
603
[self accessDataSourceWithBlock: ^{
607
- [self prepareForReloadSections: sections];
608
-
609
604
NSMutableArray *updatedNodes = [NSMutableArray array ];
610
605
NSMutableArray *updatedIndexPaths = [NSMutableArray array ];
611
606
[self _populateFromDataSourceWithSectionIndexSet: sections mutableNodes: updatedNodes mutableIndexPaths: updatedIndexPaths];
@@ -615,7 +610,9 @@ - (void)reloadSections:(NSIndexSet *)sections withAnimationOptions:(ASDataContro
615
610
// at this time. Thus _editingNodes could be empty and crash in ASIndexPathsForMultidimensional[...]
616
611
617
612
// Measure nodes whose views are loaded before we leave the main thread
618
- [self _layoutNodesWithMainThreadAffinity: updatedNodes atIndexPaths: updatedIndexPaths];
613
+ [self layoutLoadedNodes: updatedNodes ofKind: ASDataControllerRowNodeKind atIndexPaths: updatedIndexPaths];
614
+
615
+ [self prepareForReloadSections: sections];
619
616
620
617
[_editingTransactionQueue addOperationWithBlock: ^{
621
618
[self willReloadSections: sections];
@@ -727,7 +724,7 @@ - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDat
727
724
}
728
725
729
726
// Measure nodes whose views are loaded before we leave the main thread
730
- [self _layoutNodesWithMainThreadAffinity : nodes atIndexPaths: indexPaths];
727
+ [self layoutLoadedNodes : nodes ofKind: ASDataControllerRowNodeKind atIndexPaths: indexPaths];
731
728
732
729
[_editingTransactionQueue addOperationWithBlock: ^{
733
730
LOG (@" Edit Transaction - insertRows: %@ " , indexPaths);
@@ -777,7 +774,7 @@ - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDat
777
774
}
778
775
779
776
// Measure nodes whose views are loaded before we leave the main thread
780
- [self _layoutNodesWithMainThreadAffinity : nodes atIndexPaths: indexPaths];
777
+ [self layoutLoadedNodes : nodes ofKind: ASDataControllerRowNodeKind atIndexPaths: indexPaths];
781
778
782
779
[_editingTransactionQueue addOperationWithBlock: ^{
783
780
LOG (@" Edit Transaction - reloadRows: %@ " , indexPaths);
0 commit comments