mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
[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:
committed by
Michael Schneider
parent
3f11c67c82
commit
1d28639301
@@ -178,6 +178,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
struct {
|
struct {
|
||||||
unsigned int layoutInspectorDidChangeCollectionViewDataSource:1;
|
unsigned int layoutInspectorDidChangeCollectionViewDataSource:1;
|
||||||
unsigned int layoutInspectorDidChangeCollectionViewDelegate:1;
|
unsigned int layoutInspectorDidChangeCollectionViewDelegate:1;
|
||||||
|
unsigned int layoutInspectorScrollableDirections:1;
|
||||||
} _layoutInspectorFlags;
|
} _layoutInspectorFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,6 +455,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
|
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDataSource = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDataSource:)];
|
||||||
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
|
_layoutInspectorFlags.layoutInspectorDidChangeCollectionViewDelegate = [_layoutInspector respondsToSelector:@selector(didChangeCollectionViewDelegate:)];
|
||||||
|
_layoutInspectorFlags.layoutInspectorScrollableDirections = [_layoutInspector respondsToSelector:@selector(scrollableDirections)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
||||||
@@ -844,19 +846,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (ASScrollDirection)scrollableDirections
|
- (ASScrollDirection)scrollableDirections
|
||||||
{
|
{
|
||||||
if ([self.collectionViewLayout asdk_isFlowLayout]) {
|
if (_layoutInspectorFlags.layoutInspectorScrollableDirections) {
|
||||||
return [self flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)self.collectionViewLayout];
|
return [self.layoutInspector scrollableDirections];
|
||||||
} else {
|
} else {
|
||||||
return [self nonFlowLayoutScrollableDirections];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
|
|
||||||
return (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (ASScrollDirection)nonFlowLayoutScrollableDirections
|
|
||||||
{
|
|
||||||
ASScrollDirection scrollableDirection = ASScrollDirectionNone;
|
ASScrollDirection scrollableDirection = ASScrollDirectionNone;
|
||||||
CGFloat totalContentWidth = self.contentSize.width + self.contentInset.left + self.contentInset.right;
|
CGFloat totalContentWidth = self.contentSize.width + self.contentInset.left + self.contentInset.right;
|
||||||
CGFloat totalContentHeight = self.contentSize.height + self.contentInset.top + self.contentInset.bottom;
|
CGFloat totalContentHeight = self.contentSize.height + self.contentInset.top + self.contentInset.bottom;
|
||||||
@@ -869,6 +861,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
}
|
}
|
||||||
return scrollableDirection;
|
return scrollableDirection;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
|
||||||
|
return (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)layoutSubviews
|
- (void)layoutSubviews
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <AsyncDisplayKit/ASDimension.h>
|
#import <AsyncDisplayKit/ASDimension.h>
|
||||||
|
#import <AsyncDisplayKit/ASScrollDirection.h>
|
||||||
|
|
||||||
@class ASCollectionView;
|
@class ASCollectionView;
|
||||||
@protocol ASCollectionDataSource;
|
@protocol ASCollectionDataSource;
|
||||||
@@ -52,6 +53,11 @@ 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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -176,6 +176,11 @@ static inline ASSizeRange NodeConstrainedSizeForScrollDirection(ASCollectionView
|
|||||||
return [self layoutHasSupplementaryViewOfKind:kind inSection:section collectionView:collectionView] ? 1 : 0;
|
return [self layoutHasSupplementaryViewOfKind:kind inSection:section collectionView:collectionView] ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
return (self.layout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Private helpers
|
#pragma mark - Private helpers
|
||||||
|
|
||||||
- (CGSize)sizeForSupplementaryViewOfKind:(NSString *)kind inSection:(NSUInteger)section collectionView:(ASCollectionView *)collectionView
|
- (CGSize)sizeForSupplementaryViewOfKind:(NSString *)kind inSection:(NSUInteger)section collectionView:(ASCollectionView *)collectionView
|
||||||
|
|||||||
Reference in New Issue
Block a user