mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-06 20:54:04 +00:00
73 lines
2.2 KiB
Objective-C
73 lines
2.2 KiB
Objective-C
//
|
|
// ASPagerNode.m
|
|
// AsyncDisplayKit
|
|
//
|
|
// Created by Levi McCallum on 12/7/15.
|
|
// Copyright © 2015 Facebook. All rights reserved.
|
|
//
|
|
|
|
#import "ASPagerNode.h"
|
|
|
|
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> {
|
|
UICollectionViewFlowLayout *_flowLayout;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation ASPagerNode
|
|
|
|
- (instancetype)init
|
|
{
|
|
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
|
_flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
_flowLayout.minimumInteritemSpacing = 0;
|
|
_flowLayout.minimumLineSpacing = 0;
|
|
|
|
self = [super initWithCollectionViewLayout:_flowLayout];
|
|
if (self != nil) {
|
|
self.view.asyncDataSource = self;
|
|
self.view.asyncDelegate = self;
|
|
|
|
self.view.pagingEnabled = YES;
|
|
self.view.allowsSelection = NO;
|
|
self.view.showsVerticalScrollIndicator = NO;
|
|
self.view.showsHorizontalScrollIndicator = NO;
|
|
|
|
ASRangeTuningParameters tuningParams = { .leadingBufferScreenfuls = 1.0, .trailingBufferScreenfuls = 1.0 };
|
|
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypePreload];
|
|
[self setTuningParameters:tuningParams forRangeType:ASLayoutRangeTypeRender];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)reloadData
|
|
{
|
|
[self.view reloadData];
|
|
}
|
|
|
|
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
|
{
|
|
[self.view setTuningParameters:tuningParameters forRangeType:rangeType];
|
|
}
|
|
|
|
#pragma mark - ASCollectionViewDataSource
|
|
|
|
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
|
|
return [self.dataSource pagerNode:self nodeAtIndex:indexPath.item];
|
|
}
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
{
|
|
ASDisplayNodeAssert(self.dataSource != nil, @"ASPagerNode must have a data source to load paging nodes");
|
|
return [self.dataSource numberOfPagesInPagerNode:self];
|
|
}
|
|
|
|
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
return ASSizeRangeMake(CGSizeZero, self.view.bounds.size);
|
|
}
|
|
|
|
@end
|