mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Improve Our Handling of Flow Layout Headers/Footers (#2939)
* Rejigger our flow layout supplementary support to make more sense. * Support old protocol * Update * Update deprecation message * Undeprecate insetForSection method, because it actually _does_ still work * Update the tests * Remove irrelevant junk * Remove cast, add pragma
This commit is contained in:
@@ -22,6 +22,4 @@
|
||||
*/
|
||||
@interface BlurbNode : ASCellNode
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width;
|
||||
|
||||
@end
|
||||
|
||||
@@ -39,10 +39,6 @@ static CGFloat kTextPadding = 10.0f;
|
||||
#pragma mark -
|
||||
#pragma mark ASCellNode.
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width {
|
||||
return kFixedHeight;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
|
||||
@@ -21,6 +21,4 @@
|
||||
|
||||
@interface LoadingNode : ASCellNode
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width;
|
||||
|
||||
@end
|
||||
|
||||
@@ -39,10 +39,6 @@ static CGFloat kFixedHeight = 200.0f;
|
||||
#pragma mark -
|
||||
#pragma mark ASCellNode.
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width {
|
||||
return kFixedHeight;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
@@ -61,10 +57,6 @@ static CGFloat kFixedHeight = 200.0f;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layout {
|
||||
[super layout];
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASCenterLayoutSpec *centerSpec = [[ASCenterLayoutSpec alloc] init];
|
||||
|
||||
@@ -29,7 +29,7 @@ static const NSInteger kBatchSize = 20;
|
||||
static const CGFloat kHorizontalSectionPadding = 10.0f;
|
||||
static const CGFloat kVerticalSectionPadding = 20.0f;
|
||||
|
||||
@interface ViewController () <ASCollectionDataSource, ASCollectionDelegate, ASCollectionViewDelegateFlowLayout>
|
||||
@interface ViewController () <ASCollectionDataSource, ASCollectionDelegate, ASCollectionDelegateFlowLayout>
|
||||
{
|
||||
ASCollectionNode *_collectionNode;
|
||||
NSMutableArray *_data;
|
||||
@@ -203,27 +203,24 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - ASCollectionViewDelegateFlowLayout
|
||||
#pragma mark - ASCollectionDelegateFlowLayout
|
||||
|
||||
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
|
||||
return UIEdgeInsetsMake(kVerticalSectionPadding, kHorizontalSectionPadding, kVerticalSectionPadding, kHorizontalSectionPadding);
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
|
||||
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode referenceConstrainedSizeForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
if (section == 0) {
|
||||
CGFloat width = CGRectGetWidth(self.view.frame) - 2 * kHorizontalSectionPadding;
|
||||
return CGSizeMake(width, [BlurbNode desiredHeightForWidth:width]);
|
||||
return ASSizeRangeUnconstrained;
|
||||
} else {
|
||||
return ASSizeRangeZero;
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
|
||||
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode referenceConstrainedSizeForFooterInSection:(NSInteger)section
|
||||
{
|
||||
if (section == 0) {
|
||||
CGFloat width = CGRectGetWidth(self.view.frame);
|
||||
return CGSizeMake(width, [LoadingNode desiredHeightForWidth:width]);
|
||||
return ASSizeRangeUnconstrained;
|
||||
} else {
|
||||
return ASSizeRangeZero;
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user