[ASCollectionNode] Add scrollableDirections method to ASCollectionViewLayoutInspecting p… (#2381)

* Add scrollableDirections method to ASCollectionViewLayoutInspecting protocol

ASViewController's default method will not always return the correct scrollable
directions in cases where size changes may not have been applied. This allows
us to ignore this issue for a little while longer by allowing the layout
inspector to explicitly vend this.

* Better header, thanks @maicki!
This commit is contained in:
Garrett Moon
2016-10-14 09:39:28 -07:00
committed by Michael Schneider
parent 3f11c67c82
commit 1d28639301
3 changed files with 26 additions and 18 deletions

View File

@@ -178,6 +178,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
struct {
unsigned int layoutInspectorDidChangeCollectionViewDataSource:1;
unsigned int layoutInspectorDidChangeCollectionViewDelegate:1;
unsigned int layoutInspectorScrollableDirections:1;
} _layoutInspectorFlags;
}
@@ -454,6 +455,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
_layoutInspectorFlags.layoutInspectorScrollableDirections = [_layoutInspector respondsToSelector:@selector(scrollableDirections)];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
@@ -844,10 +846,20 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (ASScrollDirection)scrollableDirections
{
if ([self.collectionViewLayout asdk_isFlowLayout]) {
return [self flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)self.collectionViewLayout];
if (_layoutInspectorFlags.layoutInspectorScrollableDirections) {
return [self.layoutInspector scrollableDirections];
} else {
return [self nonFlowLayoutScrollableDirections];
ASScrollDirection scrollableDirection = ASScrollDirectionNone;
CGFloat totalContentWidth = self.contentSize.width + self.contentInset.left + self.contentInset.right;
CGFloat totalContentHeight = self.contentSize.height + self.contentInset.top + self.contentInset.bottom;
if (self.alwaysBounceHorizontal || totalContentWidth > self.bounds.size.width) { // Can scroll horizontally.
scrollableDirection |= ASScrollDirectionHorizontalDirections;
}
if (self.alwaysBounceVertical || totalContentHeight > self.bounds.size.height) { // Can scroll vertically.
scrollableDirection |= ASScrollDirectionVerticalDirections;
}
return scrollableDirection;
}
}
@@ -855,21 +867,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
return (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections;
}
- (ASScrollDirection)nonFlowLayoutScrollableDirections
{
ASScrollDirection scrollableDirection = ASScrollDirectionNone;
CGFloat totalContentWidth = self.contentSize.width + self.contentInset.left + self.contentInset.right;
CGFloat totalContentHeight = self.contentSize.height + self.contentInset.top + self.contentInset.bottom;
if (self.alwaysBounceHorizontal || totalContentWidth > self.bounds.size.width) { // Can scroll horizontally.
scrollableDirection |= ASScrollDirectionHorizontalDirections;
}
if (self.alwaysBounceVertical || totalContentHeight > self.bounds.size.height) { // Can scroll vertically.
scrollableDirection |= ASScrollDirectionVerticalDirections;
}
return scrollableDirection;
}
- (void)layoutSubviews
{
if (_zeroContentInsets) {