Allow UICollectionViewLayout to Provide Layout Inspector, Always Update Delegate (#3003)

* Allow UICollectionViewLayout to give us a layout inspector, always call the didChangeDelegate/didChangeDataSource on binding

* Make an assertion

* Update the tests

* Tests use actual layout inspector

* Be more consistent
This commit is contained in:
Adlai Holler
2017-02-08 22:03:13 -08:00
committed by GitHub
parent 1adfb005ca
commit a13b36d63f
8 changed files with 53 additions and 39 deletions

View File

@@ -533,19 +533,14 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
- (id<ASCollectionViewLayoutInspecting>)layoutInspector
{
if (_layoutInspector == nil) {
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
UICollectionViewLayout *layout = self.collectionViewLayout;
if (layout == nil) {
// Layout hasn't been set yet, we're still init'ing
return nil;
}
if ([layout asdk_isFlowLayout]) {
// Register the default layout inspector delegate for flow layouts only
_defaultLayoutInspector = [[ASCollectionViewFlowLayoutInspector alloc] initWithCollectionView:self flowLayout:layout];
} else {
// Register the default layout inspector delegate for custom collection view layouts
_defaultLayoutInspector = [[ASCollectionViewLayoutInspector alloc] initWithCollectionView:self];
}
_defaultLayoutInspector = [layout asdk_layoutInspector];
ASDisplayNodeAssertNotNil(_defaultLayoutInspector, @"You must not return nil from -asdk_layoutInspector. Return [super asdk_layoutInspector] if you have to! Layout: %@", layout);
// Explicitly call the setter to wire up the _layoutInspectorFlags
self.layoutInspector = _defaultLayoutInspector;
@@ -560,6 +555,13 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
_layoutInspectorFlags.didChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
_layoutInspectorFlags.didChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
if (_layoutInspectorFlags.didChangeCollectionViewDataSource) {
[_layoutInspector didChangeCollectionViewDataSource:self.asyncDataSource];
}
if (_layoutInspectorFlags.didChangeCollectionViewDelegate) {
[_layoutInspector didChangeCollectionViewDelegate:self.asyncDelegate];
}
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType