Skip to content

Commit 8fa092f

Browse files
committed
Complete overhaul of ASFlowLayoutController.
Introduced ASIndexPath for efficient handling of index paths in C++ vectors, while maintaining the readability of ".section" and ".row" instead of ".first" and ".second" inside of complicated business logic. Confirmed that the working range calls are firing appropriately during ASTableViewStressTest, including the deallocation of the rich text placeholders provided by ASTextNode.
1 parent 57465c7 commit 8fa092f

10 files changed

+227
-170
lines changed

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ - (void)clearContents
13371337
{
13381338
self.layer.contents = nil;
13391339
_placeholderLayer.contents = nil;
1340+
_placeholderImage = nil;
13401341
}
13411342

13421343
- (void)recursivelyClearContents

AsyncDisplayKit/ASTableView.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ @interface ASTableView () <ASRangeControllerDelegate, ASDataControllerSource> {
117117
_ASTableViewProxy *_proxyDelegate;
118118

119119
ASDataController *_dataController;
120-
ASCollectionViewLayoutController *_layoutController;
120+
ASFlowLayoutController *_layoutController;
121121

122122
ASRangeController *_rangeController;
123123

@@ -159,16 +159,17 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
159159

160160
- (void)configureWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled
161161
{
162-
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
163-
_layoutController = [[ASCollectionViewLayoutController alloc] initWithScrollView:self collectionViewLayout:flowLayout];
164-
162+
_layoutController = [[ASFlowLayoutController alloc] initWithScrollOption:ASFlowLayoutDirectionVertical];
163+
165164
_rangeController = [[ASRangeController alloc] init];
166165
_rangeController.layoutController = _layoutController;
167166
_rangeController.delegate = self;
168167

169168
_dataController = [[ASDataController alloc] initWithAsyncDataFetching:asyncDataFetchingEnabled];
170169
_dataController.dataSource = self;
171170
_dataController.delegate = _rangeController;
171+
172+
_layoutController.dataSource = _dataController;
172173

173174
_asyncDataFetchingEnabled = asyncDataFetchingEnabled;
174175
_asyncDataSourceLocked = NO;

AsyncDisplayKit/Details/ASCollectionViewLayoutController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@
1414
@interface ASCollectionViewLayoutController : ASAbstractLayoutController
1515

1616
- (instancetype)initWithCollectionView:(ASCollectionView *)collectionView;
17-
- (instancetype)initWithScrollView:(UIScrollView *)scrollView collectionViewLayout:(UICollectionViewLayout *)layout;
1817

1918
@end

AsyncDisplayKit/Details/ASCollectionViewLayoutController.mm

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ - (instancetype)initWithCollectionView:(ASCollectionView *)collectionView
7878
return self;
7979
}
8080

81-
- (instancetype)initWithScrollView:(UIScrollView *)scrollView collectionViewLayout:(UICollectionViewLayout *)layout
82-
{
83-
if (!(self = [super init])) {
84-
return nil;
85-
}
86-
87-
_scrollableDirections = ASScrollDirectionVerticalDirections;
88-
_scrollView = scrollView;
89-
_collectionViewLayout = layout;
90-
_updateRangeBoundsIndexedByRangeType = std::vector<CGRect>(ASLayoutRangeTypeCount);
91-
return self;
92-
}
93-
94-
9581
#pragma mark -
9682
#pragma mark Index Paths in Range
9783

AsyncDisplayKit/Details/ASDataController.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <UIKit/UIKit.h>
1010
#import <AsyncDisplayKit/ASDealloc2MainObject.h>
11-
11+
#import "ASFlowLayoutController.h"
1212

1313
@class ASCellNode;
1414
@class ASDataController;
@@ -97,7 +97,8 @@ typedef NSUInteger ASDataControllerAnimationOptions;
9797
* will be updated asynchronously. The dataSource must be updated to reflect the changes before these methods has been called.
9898
* For each data updatin, the corresponding methods in delegate will be called.
9999
*/
100-
@interface ASDataController : ASDealloc2MainObject
100+
@protocol ASFlowLayoutControllerDataSource;
101+
@interface ASDataController : ASDealloc2MainObject <ASFlowLayoutControllerDataSource>
101102

102103
/**
103104
Data source for fetching data info.
@@ -167,4 +168,6 @@ typedef NSUInteger ASDataControllerAnimationOptions;
167168

168169
- (NSArray *)nodesAtIndexPaths:(NSArray *)indexPaths;
169170

171+
- (NSArray *)completedNodes; // This provides efficient access to the entire _completedNodes multidimensional array.
172+
170173
@end

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ - (instancetype)initWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled
5454
_pendingEditCommandBlocks = [NSMutableArray array];
5555

5656
_editingTransactionQueue = [[NSOperationQueue alloc] init];
57-
_editingTransactionQueue.qualityOfService = NSQualityOfServiceUserInitiated;
5857
_editingTransactionQueue.maxConcurrentOperationCount = 1; // Serial queue
5958
_editingTransactionQueue.name = @"org.AsyncDisplayKit.ASDataController.editingTransactionQueue";
6059

@@ -553,17 +552,15 @@ - (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath
553552
- (NSArray *)nodesAtIndexPaths:(NSArray *)indexPaths
554553
{
555554
ASDisplayNodeAssertMainThread();
556-
557-
// Make sure that any asynchronous layout operations have finished so that those nodes are present.
558-
// Otherwise a failure case could be:
559-
// - Reload section 2, deleting all current nodes in that section.
560-
// - New nodes are created and sizing is triggered, but they are not yet added to _completedNodes.
561-
// - This method is called and includes an indexPath in section 2.
562-
// - Unless we wait for the layout group to finish, we will crash with array out of bounds looking for the index in _completedNodes.
563-
564555
return ASFindElementsInMultidimensionalArrayAtIndexPaths(_completedNodes, [indexPaths sortedArrayUsingSelector:@selector(compare:)]);
565556
}
566557

558+
- (NSArray *)completedNodes
559+
{
560+
ASDisplayNodeAssertMainThread();
561+
return _completedNodes;
562+
}
563+
567564
#pragma mark - Dealloc
568565

569566
- (void)dealloc

AsyncDisplayKit/Details/ASFlowLayoutController.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ typedef NS_ENUM(NSUInteger, ASFlowLayoutDirection) {
1515
ASFlowLayoutDirectionHorizontal,
1616
};
1717

18+
@protocol ASFlowLayoutControllerDataSource
19+
20+
- (NSArray *)completedNodes; // This provides access to ASDataController's _completedNodes multidimensional array.
21+
22+
@end
23+
1824
/**
19-
* The controller for flow layout.
25+
* An optimized flow layout controller that supports only vertical or horizontal scrolling, not simultaneously two-dimensional scrolling.
26+
* It is used for all ASTableViews, and may be used with ASCollectionView.
2027
*/
2128
@interface ASFlowLayoutController : ASAbstractLayoutController
2229

2330
@property (nonatomic, readonly, assign) ASFlowLayoutDirection layoutDirection;
31+
@property (nonatomic) id <ASFlowLayoutControllerDataSource> dataSource;
2432

2533
- (instancetype)initWithScrollOption:(ASFlowLayoutDirection)layoutDirection;
2634

0 commit comments

Comments
 (0)