Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit e69a475

Browse files
author
Adlai Holler
authored
Minor Collection Simplifications (#2906)
* Minor collection simplifications * Remove didChangeCollectionViewDataSource call, restrict subclassing ASCollectionViewFlowLayoutInspector
1 parent d41ef55 commit e69a475

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ typedef NS_ENUM(NSUInteger, ASCollectionViewInvalidationStyle) {
5757
};
5858

5959
static const NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone;
60-
static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
60+
61+
/// Used for all cells and supplementaries. UICV keys by supp-kind+reuseID so this is plenty.
62+
static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
6163

6264
#pragma mark -
6365
#pragma mark ASCellNode<->UICollectionViewCell bridging.
@@ -338,7 +340,7 @@ - (instancetype)_initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionV
338340
_cellsForVisibilityUpdates = [NSMutableSet set];
339341
self.backgroundColor = [UIColor whiteColor];
340342

341-
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kCellReuseIdentifier];
343+
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kReuseIdentifier];
342344

343345
if (!AS_AT_LEAST_IOS9) {
344346
_retainedLayer = self.layer;
@@ -780,8 +782,7 @@ - (void)registerSupplementaryNodeOfKind:(NSString *)elementKind
780782
{
781783
ASDisplayNodeAssert(elementKind != nil, @"A kind is needed for supplementary node registration");
782784
[_registeredSupplementaryKinds addObject:elementKind];
783-
[self registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:elementKind
784-
withReuseIdentifier:[self __reuseIdentifierForKind:elementKind]];
785+
[self registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:elementKind withReuseIdentifier:kReuseIdentifier];
785786
}
786787

787788
- (void)insertSections:(NSIndexSet *)sections
@@ -844,11 +845,6 @@ - (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)
844845
[_dataController moveRowAtIndexPath:indexPath toIndexPath:newIndexPath withAnimationOptions:kASCollectionViewAnimationNone];
845846
}
846847

847-
- (NSString *)__reuseIdentifierForKind:(NSString *)kind
848-
{
849-
return [@"_ASCollectionSupplementaryView_" stringByAppendingString:kind];
850-
}
851-
852848
#pragma mark -
853849
#pragma mark Intercepted selectors.
854850

@@ -870,8 +866,7 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
870866

871867
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
872868
{
873-
NSString *identifier = [self __reuseIdentifierForKind:kind];
874-
UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];
869+
UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kReuseIdentifier forIndexPath:indexPath];
875870
ASCellNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath];
876871
ASDisplayNodeAssert(node != nil, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self);
877872
[_rangeController configureContentView:view forCellNode:node];
@@ -882,7 +877,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
882877

883878
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
884879
{
885-
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
880+
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:kReuseIdentifier forIndexPath:indexPath];
886881

887882
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
888883
cell.node = node;

AsyncDisplayKit/Details/ASCollectionViewFlowLayoutInspector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
1717
/**
1818
* A layout inspector implementation specific for the sizing behavior of UICollectionViewFlowLayouts
1919
*/
20+
AS_SUBCLASSING_RESTRICTED
2021
@interface ASCollectionViewFlowLayoutInspector : NSObject <ASCollectionViewLayoutInspecting>
2122

2223
@property (nonatomic, weak, readonly) UICollectionViewFlowLayout *layout;

AsyncDisplayKit/Details/ASCollectionViewFlowLayoutInspector.m

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ @implementation ASCollectionViewFlowLayoutInspector {
2929
unsigned int implementsConstrainedSizeForNodeAtIndexPathDeprecated:1;
3030
unsigned int implementsConstrainedSizeForItemAtIndexPath:1;
3131
} _delegateFlags;
32-
33-
struct {
34-
unsigned int implementsNumberOfSectionsInCollectionView:1;
35-
} _dataSourceFlags;
3632
}
3733

3834
#pragma mark Lifecycle
@@ -44,7 +40,6 @@ - (instancetype)initWithCollectionView:(ASCollectionView *)collectionView flowLa
4440

4541
self = [super init];
4642
if (self != nil) {
47-
[self didChangeCollectionViewDataSource:collectionView.asyncDataSource];
4843
[self didChangeCollectionViewDelegate:collectionView.asyncDelegate];
4944
_layout = flowLayout;
5045
}
@@ -65,15 +60,6 @@ - (void)didChangeCollectionViewDelegate:(id<ASCollectionDelegate>)delegate;
6560
}
6661
}
6762

68-
- (void)didChangeCollectionViewDataSource:(id<ASCollectionDataSource>)dataSource
69-
{
70-
if (dataSource == nil) {
71-
memset(&_dataSourceFlags, 0, sizeof(_dataSourceFlags));
72-
} else {
73-
_dataSourceFlags.implementsNumberOfSectionsInCollectionView = [dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)];
74-
}
75-
}
76-
7763
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
7864
{
7965
if (_delegateFlags.implementsConstrainedSizeForItemAtIndexPath) {

Base/ASBaseDefines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@
190190
#define AS_NOESCAPE
191191
#endif
192192

193+
#if __has_attribute(objc_subclassing_restricted)
194+
#define AS_SUBCLASSING_RESTRICTED __attribute__((objc_subclassing_restricted))
195+
#else
196+
#define AS_SUBCLASSING_RESTRICTED
197+
#endif
198+
193199
/// Ensure that class is of certain kind
194200
#define ASDynamicCast(x, c) ({ \
195201
id __val = x;\

0 commit comments

Comments
 (0)