mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-23 19:31:21 +08:00
Fix passing wrong constrained size to nodes
In _layoutNodesFromContexts:ofKind:completion: we pass the full array of contexts to _layoutNodes:fromContexts:atIndexesOfRange:ofKind: but for nodes we pass a subarray of nodes instead based on the batchCount. As batchRange we always start from 0 to batchCount. We now use the same indexes that we use to create the subarray of nodes to get a subarray of contexts that we pass to _layoutNodes:fromContexts:atIndexesOfRange:ofKind:.
This commit is contained in:
@@ -191,14 +191,16 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
for (NSUInteger j = 0; j < nodeCount; j += kASDataControllerSizingCountPerProcessor) {
|
||||
NSInteger batchCount = MIN(kASDataControllerSizingCountPerProcessor, nodeCount - j);
|
||||
|
||||
__block NSArray *subarray;
|
||||
// Get subcontexts for the range of nodes that will be allocated
|
||||
NSArray *subcontexts = [contexts subarrayWithRange:NSMakeRange(j, batchCount)];
|
||||
|
||||
// Allocate nodes concurrently.
|
||||
__block NSArray *subarray;
|
||||
dispatch_block_t allocationBlock = ^{
|
||||
__strong ASCellNode **allocatedNodeBuffer = (__strong ASCellNode **)calloc(batchCount, sizeof(ASCellNode *));
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_apply(batchCount, queue, ^(size_t i) {
|
||||
unsigned long k = j + i;
|
||||
ASCellNode *node = [contexts[k] allocateNode];
|
||||
ASCellNode *node = [subcontexts[i] allocateNode];
|
||||
if (node == nil) {
|
||||
ASDisplayNodeAssertNotNil(node, @"Node block created nil node; %@, %@", self, self.dataSource);
|
||||
node = [[ASCellNode alloc] init]; // Fallback to avoid crash for production apps.
|
||||
@@ -225,11 +227,11 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
});
|
||||
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
|
||||
|
||||
[self _layoutNodes:subarray fromContexts:contexts atIndexesOfRange:batchRange ofKind:kind];
|
||||
[self _layoutNodes:subarray fromContexts:subcontexts atIndexesOfRange:batchRange ofKind:kind];
|
||||
} else {
|
||||
allocationBlock();
|
||||
[_mainSerialQueue performBlockOnMainThread:^{
|
||||
[self _layoutNodes:subarray fromContexts:contexts atIndexesOfRange:batchRange ofKind:kind];
|
||||
[self _layoutNodes:subarray fromContexts:subcontexts atIndexesOfRange:batchRange ofKind:kind];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user