[ASCollectionViewLayoutInspecting] make -scrollableDirections required (#2543)

* [ASCollectionViewLayoutInspecting] make -scrollableDirections a required method

* doh!

* fixed?

* add assert per @appleguy's comment

* use self.layoutInspector, add check at the start of didChangeBounds...
This commit is contained in:
Hannah Troisi
2016-11-08 20:48:16 -08:00
committed by Adlai Holler
parent 55b5dff80c
commit edf2b669ae
4 changed files with 21 additions and 24 deletions

View File

@@ -212,7 +212,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
struct {
unsigned int didChangeCollectionViewDataSource:1;
unsigned int didChangeCollectionViewDelegate:1;
unsigned int scrollableDirections:1;
} _layoutInspectorFlags;
}
@@ -515,7 +514,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
_layoutInspectorFlags.didChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
_layoutInspectorFlags.didChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
_layoutInspectorFlags.scrollableDirections = [_layoutInspector respondsToSelector:@selector(scrollableDirections)];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
@@ -1117,23 +1115,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
- (ASScrollDirection)scrollableDirections
{
//Cache results of layoutInspector to ensure flags are up to date if getter lazily loads a new one.
id<ASCollectionViewLayoutInspecting> layoutInspector = self.layoutInspector;
if (_layoutInspectorFlags.scrollableDirections) {
return [layoutInspector scrollableDirections];
} else {
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;
}
ASDisplayNodeAssertNotNil(self.layoutInspector, @"Layout inspector should be assigned.");
return [self.layoutInspector scrollableDirections];
}
- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
@@ -1672,6 +1655,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
*/
- (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds
{
if (self.collectionViewLayout == nil) {
return;
}
CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
if (CGSizeEqualToSize(lastUsedSize, newBounds.size)) {
return;