mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[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:
committed by
Adlai Holler
parent
55b5dff80c
commit
edf2b669ae
@@ -212,7 +212,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
struct {
|
struct {
|
||||||
unsigned int didChangeCollectionViewDataSource:1;
|
unsigned int didChangeCollectionViewDataSource:1;
|
||||||
unsigned int didChangeCollectionViewDelegate:1;
|
unsigned int didChangeCollectionViewDelegate:1;
|
||||||
unsigned int scrollableDirections:1;
|
|
||||||
} _layoutInspectorFlags;
|
} _layoutInspectorFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,7 +514,6 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
_layoutInspectorFlags.didChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
|
_layoutInspectorFlags.didChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
|
||||||
_layoutInspectorFlags.didChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
|
_layoutInspectorFlags.didChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
|
||||||
_layoutInspectorFlags.scrollableDirections = [_layoutInspector respondsToSelector:@selector(scrollableDirections)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
||||||
@@ -1117,23 +1115,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (ASScrollDirection)scrollableDirections
|
- (ASScrollDirection)scrollableDirections
|
||||||
{
|
{
|
||||||
//Cache results of layoutInspector to ensure flags are up to date if getter lazily loads a new one.
|
ASDisplayNodeAssertNotNil(self.layoutInspector, @"Layout inspector should be assigned.");
|
||||||
id<ASCollectionViewLayoutInspecting> layoutInspector = self.layoutInspector;
|
return [self.layoutInspector scrollableDirections];
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
|
- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
|
||||||
@@ -1672,6 +1655,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
*/
|
*/
|
||||||
- (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds
|
- (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds
|
||||||
{
|
{
|
||||||
|
if (self.collectionViewLayout == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
|
CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
|
||||||
if (CGSizeEqualToSize(lastUsedSize, newBounds.size)) {
|
if (CGSizeEqualToSize(lastUsedSize, newBounds.size)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*/
|
*/
|
||||||
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath;
|
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the directions in which your collection view can scroll
|
||||||
|
*/
|
||||||
|
- (ASScrollDirection)scrollableDirections;
|
||||||
|
|
||||||
@optional
|
@optional
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,11 +58,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*/
|
*/
|
||||||
- (void)didChangeCollectionViewDataSource:(nullable id<ASCollectionDataSource>)dataSource;
|
- (void)didChangeCollectionViewDataSource:(nullable id<ASCollectionDataSource>)dataSource;
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the directions in which your collection view can scroll
|
|
||||||
*/
|
|
||||||
- (ASScrollDirection)scrollableDirections;
|
|
||||||
|
|
||||||
#pragma mark Deprecated Methods
|
#pragma mark Deprecated Methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -79,6 +79,12 @@ static inline ASSizeRange NodeConstrainedSizeForScrollDirection(ASCollectionView
|
|||||||
return NodeConstrainedSizeForScrollDirection(collectionView);
|
return NodeConstrainedSizeForScrollDirection(collectionView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
ASDisplayNodeAssert(NO, @"layoutInspector object must implement -scrollableDirections %@", self);
|
||||||
|
return ASScrollDirectionNone;
|
||||||
|
}
|
||||||
|
|
||||||
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForSupplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForSupplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssert(NO, @"To support supplementary nodes in ASCollectionView, it must have a layoutInspector for layout inspection. (See ASCollectionViewFlowLayoutInspector for an example.)");
|
ASDisplayNodeAssert(NO, @"To support supplementary nodes in ASCollectionView, it must have a layoutInspector for layout inspection. (See ASCollectionViewFlowLayoutInspector for an example.)");
|
||||||
|
|||||||
@@ -214,6 +214,11 @@
|
|||||||
return ASSizeRangeMake(CGSizeZero, [layout _headerSizeForSection:indexPath.section]);
|
return ASSizeRangeMake(CGSizeZero, [layout _headerSizeForSection:indexPath.section]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
return ASScrollDirectionVerticalDirections;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asks the inspector for the number of supplementary views for the given kind in the specified section.
|
* Asks the inspector for the number of supplementary views for the given kind in the specified section.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user