mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[Umbrella] ASCollectionView -> ASCollectionNode Migration, Separate Index Spaces (#2372)
* Separate dataSource & UIKit index spaces Beef up our supplementary node support Make the API way better Go nuts Add a unit test for UICollectionView's handling of reloadData inside batch updates Wrap indexPathForNode: in a cache Convert index paths in delegate methods Go back on table view Put collection view back Switch up the API Move most ASCollectionView API to ASCollectionNode Move most table logic over to ASTableNode Do the things More conversion work Keep on keepin' on Get table view delegate API done More porting Simplify Clear the delegate More cleanup Move more stuff around Remove pointless file Re-add some API Put back more API Use the right flag * Some cleanup * Remove incorrect comment * Tweak the API * Put back a couple methods * update example projects (note: ASCollectionView deprecation warnings expected) * change reloadDataWithCompletion:nil --> reloadData * Clean up rebase * Make deprecated numberOfItemsInSection methods optional * Use the right flag * Address nits * update ASDKTube, ASDKgram & ASViewController examples
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
|
||||
static NSUInteger kNumberOfImages = 14;
|
||||
|
||||
@interface ViewController () <ASCollectionViewDataSource, MosaicCollectionViewLayoutDelegate>
|
||||
@interface ViewController () <ASCollectionDataSource, ASCollectionDelegate>
|
||||
{
|
||||
NSMutableArray *_sections;
|
||||
ASCollectionView *_collectionView;
|
||||
ASCollectionNode *_collectionNode;
|
||||
MosaicCollectionViewLayoutInspector *_layoutInspector;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ static NSUInteger kNumberOfImages = 14;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
if (!(self = [super initWithNode:_collectionNode]))
|
||||
return nil;
|
||||
|
||||
_sections = [NSMutableArray array];
|
||||
@@ -59,44 +59,37 @@ static NSUInteger kNumberOfImages = 14;
|
||||
|
||||
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
|
||||
|
||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||
_collectionView.asyncDataSource = self;
|
||||
_collectionView.asyncDelegate = self;
|
||||
_collectionView.layoutInspector = _layoutInspector;
|
||||
_collectionView.backgroundColor = [UIColor whiteColor];
|
||||
_collectionNode.dataSource = self;
|
||||
_collectionNode.delegate = self;
|
||||
_collectionNode.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||
[_collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
_collectionView.asyncDataSource = nil;
|
||||
_collectionView.asyncDelegate = nil;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self.view addSubview:_collectionView];
|
||||
_collectionNode.view.layoutInspector = _layoutInspector;
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews
|
||||
- (void)dealloc
|
||||
{
|
||||
_collectionView.frame = self.view.bounds;
|
||||
_collectionNode.dataSource = nil;
|
||||
_collectionNode.delegate = nil;
|
||||
}
|
||||
|
||||
- (void)reloadTapped
|
||||
{
|
||||
[_collectionView reloadData];
|
||||
[_collectionNode reloadData];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark ASCollectionView data source.
|
||||
|
||||
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
UIImage *image = _sections[indexPath.section][indexPath.item];
|
||||
return ^{
|
||||
@@ -105,7 +98,7 @@ static NSUInteger kNumberOfImages = 14;
|
||||
}
|
||||
|
||||
|
||||
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSDictionary *textAttributes = @{
|
||||
NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline],
|
||||
@@ -117,17 +110,17 @@ static NSUInteger kNumberOfImages = 14;
|
||||
return textCellNode;
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(ASCollectionNode *)collectionNode
|
||||
{
|
||||
return _sections.count;
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
- (NSInteger)collectionView:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return [_sections[section] count];
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (CGSize)collectionView:(ASCollectionNode *)collectionNode layout:(UICollectionViewLayout *)collectionViewLayout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [(UIImage *)_sections[indexPath.section][indexPath.item] size];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user