Revert "[ASCollectionView] Add a "Null Object" for a layout inspector if custom layout is given but no layout inspector" (#1713)

This commit is contained in:
appleguy
2016-06-04 22:49:10 -07:00
parent 5289b1e11e
commit 4804f429b9
4 changed files with 40 additions and 73 deletions

View File

@@ -98,7 +98,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
ASCollectionDataController *_dataController;
ASRangeController *_rangeController;
ASCollectionViewLayoutController *_layoutController;
id<ASCollectionViewLayoutInspecting> _defaultLayoutInspector;
ASCollectionViewFlowLayoutInspector *_flowLayoutInspector;
NSMutableSet *_cellsForVisibilityUpdates;
id<ASCollectionViewLayoutFacilitatorProtocol> _layoutFacilitator;
@@ -246,19 +246,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
// and should not trigger a relayout.
_ignoreMaxSizeChange = CGSizeEqualToSize(_maxSizeForNodesConstrainedSize, CGSizeZero);
// Register the default layout inspector delegate for flow layouts only, custom layouts
// will need to roll their own ASCollectionViewLayoutInspecting implementation and set a layout delegate
if ([layout asdk_isFlowLayout]) {
// Register the default layout inspector delegate for flow layouts only
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
ASDisplayNodeAssertNotNil(layout, @"Collection view layout must be a flow layout to use the built-in inspector");
_defaultLayoutInspector = [[ASCollectionViewFlowLayoutInspector alloc] initWithCollectionView:self flowLayout:layout];
} else {
// Custom layouts will need to roll their own ASCollectionViewLayoutInspecting implementation and set a layout
// delegate. In the meantime ASDK provides a custom layout inspector that does not provide any implementation
// and asserts for methods that should be implemented in the <ASCollectionViewLayoutInspecting>
_defaultLayoutInspector = [[ASCollectionViewCustomLayoutInspector alloc] init];
_layoutInspector = [self flowLayoutInspector];
}
_layoutInspector = _defaultLayoutInspector;
_layoutFacilitator = layoutFacilitator;
_proxyDelegate = [[ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self];
@@ -285,6 +277,19 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[self setAsyncDataSource:nil];
}
/**
* A layout inspector implementation specific for the sizing behavior of UICollectionViewFlowLayouts
*/
- (ASCollectionViewFlowLayoutInspector *)flowLayoutInspector
{
if (_flowLayoutInspector == nil) {
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
ASDisplayNodeAssertNotNil(layout, @"Collection view layout must be a flow layout to use the built-in inspector");
_flowLayoutInspector = [[ASCollectionViewFlowLayoutInspector alloc] initWithCollectionView:self flowLayout:layout];
}
return _flowLayoutInspector;
}
#pragma mark -
#pragma mark Overrides.
@@ -404,9 +409,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
if ([_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)]) {
[_layoutInspector didChangeCollectionViewDelegate:asyncDelegate];
}
[_layoutInspector didChangeCollectionViewDelegate:asyncDelegate];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
@@ -888,21 +891,28 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (ASSizeRange)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
{
ASSizeRange constrainedSize = [_layoutInspector collectionView:self constrainedSizeForNodeAtIndexPath:indexPath];
ASSizeRange constrainedSize = kInvalidSizeRange;
if (_layoutInspector) {
constrainedSize = [_layoutInspector collectionView:self constrainedSizeForNodeAtIndexPath:indexPath];
}
if (!ASSizeRangeEqualToSizeRange(constrainedSize, kInvalidSizeRange)) {
return constrainedSize;
}
CGSize maxSize = _maxSizeForNodesConstrainedSize;
if (CGSizeEqualToSize(_maxSizeForNodesConstrainedSize, CGSizeZero)) {
maxSize = self.bounds.size;
}
if (ASScrollDirectionContainsHorizontalDirection([self scrollableDirections])) {
maxSize.width = FLT_MAX;
// TODO: Move this logic into the flow layout inspector. Create a simple inspector for non-flow layouts that don't
// implement a custom inspector.
if (_asyncDataSourceFlags.asyncDataSourceConstrainedSizeForNode) {
constrainedSize = [_asyncDataSource collectionView:self constrainedSizeForNodeAtIndexPath:indexPath];
} else {
maxSize.height = FLT_MAX;
CGSize maxSize = CGSizeEqualToSize(_maxSizeForNodesConstrainedSize, CGSizeZero) ? self.bounds.size : _maxSizeForNodesConstrainedSize;
if (ASScrollDirectionContainsHorizontalDirection([self scrollableDirections])) {
maxSize.width = FLT_MAX;
} else {
maxSize.height = FLT_MAX;
}
constrainedSize = ASSizeRangeMake(CGSizeZero, maxSize);
}
constrainedSize = ASSizeRangeMake(CGSizeZero, maxSize);
return constrainedSize;
}
@@ -964,16 +974,19 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (ASSizeRange)dataController:(ASCollectionDataController *)dataController constrainedSizeForSupplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssert(_layoutInspector != nil, @"To support supplementary nodes in ASCollectionView, it must have a layoutDelegate for layout inspection. (See ASCollectionViewFlowLayoutInspector for an example.)");
return [_layoutInspector collectionView:self constrainedSizeForSupplementaryNodeOfKind:kind atIndexPath:indexPath];
}
- (NSUInteger)dataController:(ASCollectionDataController *)dataController supplementaryNodesOfKind:(NSString *)kind inSection:(NSUInteger)section
{
ASDisplayNodeAssert(_layoutInspector != nil, @"To support supplementary nodes in ASCollectionView, it must have a layoutDelegate for layout inspection. (See ASCollectionViewFlowLayoutInspector for an example.)");
return [_layoutInspector collectionView:self supplementaryNodesOfKind:kind inSection:section];
}
- (NSUInteger)dataController:(ASCollectionDataController *)dataController numberOfSectionsForSupplementaryNodeOfKind:(NSString *)kind;
{
ASDisplayNodeAssert(_layoutInspector != nil, @"To support supplementary nodes in ASCollectionView, it must have a layoutDelegate for layout inspection. (See ASCollectionViewFlowLayoutInspector for an example.)");
return [_layoutInspector collectionView:self numberOfSectionsForSupplementaryNodeOfKind:kind];
}