mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +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:
@@ -17,6 +17,7 @@
|
||||
#import "ASInternalHelpers.h"
|
||||
#import "ASCellNode+Internal.h"
|
||||
#import "AsyncDisplayKit+Debug.h"
|
||||
#import "ASTableView+Undeprecated.h"
|
||||
|
||||
#pragma mark - _ASTablePendingState
|
||||
|
||||
@@ -70,7 +71,7 @@
|
||||
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass
|
||||
{
|
||||
ASDisplayNodeViewBlock tableViewBlock = ^UIView *{
|
||||
return [[ASTableView alloc] _initWithFrame:frame style:style dataControllerClass:dataControllerClass ownedByNode:YES];
|
||||
return [[ASTableView alloc] _initWithFrame:frame style:style dataControllerClass:dataControllerClass];
|
||||
};
|
||||
|
||||
if (self = [super initWithViewBlock:tableViewBlock]) {
|
||||
@@ -109,6 +110,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.delegate = nil;
|
||||
self.dataSource = nil;
|
||||
}
|
||||
|
||||
- (ASTableView *)view
|
||||
{
|
||||
return (ASTableView *)[super view];
|
||||
@@ -117,13 +124,13 @@
|
||||
- (void)clearContents
|
||||
{
|
||||
[super clearContents];
|
||||
[self.view clearContents];
|
||||
[self.rangeController clearContents];
|
||||
}
|
||||
|
||||
- (void)clearFetchedData
|
||||
{
|
||||
[super clearFetchedData];
|
||||
[self.view clearFetchedData];
|
||||
[self.rangeController clearFetchedData];
|
||||
}
|
||||
|
||||
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState
|
||||
@@ -148,6 +155,18 @@
|
||||
|
||||
#pragma mark Setter / Getter
|
||||
|
||||
// TODO: Implement this without the view.
|
||||
- (ASDataController *)dataController
|
||||
{
|
||||
return self.view.dataController;
|
||||
}
|
||||
|
||||
// TODO: Implement this without the view.
|
||||
- (ASRangeController *)rangeController
|
||||
{
|
||||
return self.view.rangeController;
|
||||
}
|
||||
|
||||
- (_ASTablePendingState *)pendingState
|
||||
{
|
||||
if (!_pendingState && ![self isNodeLoaded]) {
|
||||
@@ -191,6 +210,7 @@
|
||||
if ([self pendingState]) {
|
||||
return _pendingState.dataSource;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
return self.view.asyncDataSource;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +223,7 @@
|
||||
_pendingState.rangeMode = rangeMode;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
[self.view.rangeController updateCurrentRangeWithMode:rangeMode];
|
||||
[self.rangeController updateCurrentRangeWithMode:rangeMode];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,4 +231,117 @@
|
||||
|
||||
ASEnvironmentCollectionTableSetEnvironmentState(_environmentStateLock)
|
||||
|
||||
#pragma mark - Range Tuning
|
||||
|
||||
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
|
||||
{
|
||||
return [self.rangeController tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
|
||||
}
|
||||
|
||||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
|
||||
{
|
||||
[self.rangeController setTuningParameters:tuningParameters forRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
|
||||
}
|
||||
|
||||
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
|
||||
{
|
||||
return [self.rangeController tuningParametersForRangeMode:rangeMode rangeType:rangeType];
|
||||
}
|
||||
|
||||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
|
||||
{
|
||||
return [self.rangeController setTuningParameters:tuningParameters forRangeMode:rangeMode rangeType:rangeType];
|
||||
}
|
||||
|
||||
#pragma mark - Querying Data
|
||||
|
||||
- (NSInteger)numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return [self.dataController numberOfRowsInSection:section];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSections
|
||||
{
|
||||
return [self.dataController numberOfSections];
|
||||
}
|
||||
|
||||
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode
|
||||
{
|
||||
return [self.dataController indexPathForNode:cellNode];
|
||||
}
|
||||
|
||||
- (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [self.dataController nodeAtIndexPath:indexPath];
|
||||
}
|
||||
|
||||
#pragma mark - Editing
|
||||
|
||||
- (void)reloadDataWithCompletion:(void (^)())completion
|
||||
{
|
||||
[self.view reloadDataWithCompletion:completion];
|
||||
}
|
||||
|
||||
- (void)reloadData
|
||||
{
|
||||
[self reloadDataWithCompletion:nil];
|
||||
}
|
||||
|
||||
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion
|
||||
{
|
||||
[self.view beginUpdates];
|
||||
updates();
|
||||
[self.view endUpdatesAnimated:animated completion:completion];
|
||||
}
|
||||
|
||||
- (void)performBatchUpdates:(void (^)())updates completion:(void (^)(BOOL))completion
|
||||
{
|
||||
[self performBatchAnimated:YES updates:updates completion:completion];
|
||||
}
|
||||
|
||||
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view insertSections:sections withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view deleteSections:sections withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view reloadSections:sections withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection
|
||||
{
|
||||
[self.view moveSection:section toSection:newSection];
|
||||
}
|
||||
|
||||
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
|
||||
{
|
||||
[self.view reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
|
||||
{
|
||||
[self.view moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
|
||||
}
|
||||
|
||||
- (void)waitUntilAllUpdatesAreCommitted
|
||||
{
|
||||
[self.view waitUntilAllUpdatesAreCommitted];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user