Minor Collection Simplifications (#2906)

* Minor collection simplifications

* Remove didChangeCollectionViewDataSource call, restrict subclassing ASCollectionViewFlowLayoutInspector
This commit is contained in:
Adlai Holler
2017-01-19 13:57:03 -08:00
committed by GitHub
parent d41ef55cd7
commit e69a475d2b
4 changed files with 14 additions and 26 deletions

View File

@@ -57,7 +57,9 @@ typedef NS_ENUM(NSUInteger, ASCollectionViewInvalidationStyle) {
};
static const NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone;
static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
/// Used for all cells and supplementaries. UICV keys by supp-kind+reuseID so this is plenty.
static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
#pragma mark -
#pragma mark ASCellNode<->UICollectionViewCell bridging.
@@ -338,7 +340,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
_cellsForVisibilityUpdates = [NSMutableSet set];
self.backgroundColor = [UIColor whiteColor];
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kCellReuseIdentifier];
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kReuseIdentifier];
if (!AS_AT_LEAST_IOS9) {
_retainedLayer = self.layer;
@@ -780,8 +782,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
{
ASDisplayNodeAssert(elementKind != nil, @"A kind is needed for supplementary node registration");
[_registeredSupplementaryKinds addObject:elementKind];
[self registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:elementKind
withReuseIdentifier:[self __reuseIdentifierForKind:elementKind]];
[self registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:elementKind withReuseIdentifier:kReuseIdentifier];
}
- (void)insertSections:(NSIndexSet *)sections
@@ -844,11 +845,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[_dataController moveRowAtIndexPath:indexPath toIndexPath:newIndexPath withAnimationOptions:kASCollectionViewAnimationNone];
}
- (NSString *)__reuseIdentifierForKind:(NSString *)kind
{
return [@"_ASCollectionSupplementaryView_" stringByAppendingString:kind];
}
#pragma mark -
#pragma mark Intercepted selectors.
@@ -870,8 +866,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = [self __reuseIdentifierForKind:kind];
UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];
UICollectionReusableView *view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kReuseIdentifier forIndexPath:indexPath];
ASCellNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath];
ASDisplayNodeAssert(node != nil, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self);
[_rangeController configureContentView:view forCellNode:node];
@@ -882,7 +877,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:kReuseIdentifier forIndexPath:indexPath];
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
cell.node = node;

View File

@@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* A layout inspector implementation specific for the sizing behavior of UICollectionViewFlowLayouts
*/
AS_SUBCLASSING_RESTRICTED
@interface ASCollectionViewFlowLayoutInspector : NSObject <ASCollectionViewLayoutInspecting>
@property (nonatomic, weak, readonly) UICollectionViewFlowLayout *layout;

View File

@@ -29,10 +29,6 @@
unsigned int implementsConstrainedSizeForNodeAtIndexPathDeprecated:1;
unsigned int implementsConstrainedSizeForItemAtIndexPath:1;
} _delegateFlags;
struct {
unsigned int implementsNumberOfSectionsInCollectionView:1;
} _dataSourceFlags;
}
#pragma mark Lifecycle
@@ -44,7 +40,6 @@
self = [super init];
if (self != nil) {
[self didChangeCollectionViewDataSource:collectionView.asyncDataSource];
[self didChangeCollectionViewDelegate:collectionView.asyncDelegate];
_layout = flowLayout;
}
@@ -65,15 +60,6 @@
}
}
- (void)didChangeCollectionViewDataSource:(id<ASCollectionDataSource>)dataSource
{
if (dataSource == nil) {
memset(&_dataSourceFlags, 0, sizeof(_dataSourceFlags));
} else {
_dataSourceFlags.implementsNumberOfSectionsInCollectionView = [dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)];
}
}
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
{
if (_delegateFlags.implementsConstrainedSizeForItemAtIndexPath) {

View File

@@ -190,6 +190,12 @@
#define AS_NOESCAPE
#endif
#if __has_attribute(objc_subclassing_restricted)
#define AS_SUBCLASSING_RESTRICTED __attribute__((objc_subclassing_restricted))
#else
#define AS_SUBCLASSING_RESTRICTED
#endif
/// Ensure that class is of certain kind
#define ASDynamicCast(x, c) ({ \
id __val = x;\