mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Stub out subclass hooks for section insert/remove/update/moving
This commit is contained in:
@@ -28,6 +28,11 @@
|
|||||||
NSMutableDictionary *_pendingIndexPaths;
|
NSMutableDictionary *_pendingIndexPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)willPerformInitialDataLoading
|
||||||
|
{
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
- (void)prepareForReloadData
|
- (void)prepareForReloadData
|
||||||
{
|
{
|
||||||
_pendingNodes = [NSMutableDictionary dictionary];
|
_pendingNodes = [NSMutableDictionary dictionary];
|
||||||
@@ -71,13 +76,29 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
- (void)prepareInsertSections:(NSIndexSet *)sections
|
||||||
{
|
{
|
||||||
if ([kind isEqualToString:ASDataControllerRowNodeKind]) {
|
// TODO: Implement
|
||||||
return [super constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
|
}
|
||||||
} else {
|
|
||||||
return [self.collectionDataSource dataController:self constrainedSizeForSupplementaryNodeOfKind:kind atIndexPath:indexPath];
|
- (void)willInsertSections:(NSIndexSet *)sections
|
||||||
}
|
{
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willDeleteSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willReloadSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
|
||||||
|
{
|
||||||
|
// TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableNodes:(NSMutableArray *)nodes mutableIndexPaths:(NSMutableArray *)indexPaths
|
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableNodes:(NSMutableArray *)nodes mutableIndexPaths:(NSMutableArray *)indexPaths
|
||||||
@@ -94,12 +115,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Sizing query
|
||||||
|
|
||||||
|
- (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||||
|
{
|
||||||
|
if ([kind isEqualToString:ASDataControllerRowNodeKind]) {
|
||||||
|
return [super constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
|
||||||
|
} else {
|
||||||
|
return [self.collectionDataSource dataController:self constrainedSizeForSupplementaryNodeOfKind:kind atIndexPath:indexPath];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - External supplementary store querying
|
||||||
|
|
||||||
- (ASDisplayNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
- (ASDisplayNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
return [self completedNodesOfKind:kind][indexPath.section][indexPath.item];
|
return [self completedNodesOfKind:kind][indexPath.section][indexPath.item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Private Helpers
|
||||||
|
|
||||||
- (id<ASCollectionDataControllerSource>)collectionDataSource
|
- (id<ASCollectionDataControllerSource>)collectionDataSource
|
||||||
{
|
{
|
||||||
return (id<ASCollectionDataControllerSource>)self.dataSource;
|
return (id<ASCollectionDataControllerSource>)self.dataSource;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
- (void)accessDataSourceWithBlock:(dispatch_block_t)block;
|
- (void)accessDataSourceWithBlock:(dispatch_block_t)block;
|
||||||
|
|
||||||
|
- (void)willPerformInitialDataLoading;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An opportunity for a subclass to access the data source before entering into the editing queue
|
* An opportunity for a subclass to access the data source before entering into the editing queue
|
||||||
*/
|
*/
|
||||||
@@ -37,6 +39,18 @@
|
|||||||
*/
|
*/
|
||||||
- (void)willReloadData;
|
- (void)willReloadData;
|
||||||
|
|
||||||
|
- (void)prepareInsertSections:(NSIndexSet *)sections;
|
||||||
|
|
||||||
|
- (void)willInsertSections:(NSIndexSet *)sections;
|
||||||
|
|
||||||
|
- (void)willDeleteSections:(NSIndexSet *)sections;
|
||||||
|
|
||||||
|
- (void)prepareForReloadSections:(NSIndexSet *)sections;
|
||||||
|
|
||||||
|
- (void)willReloadSections:(NSIndexSet *)sections;
|
||||||
|
|
||||||
|
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a collection of index paths for nodes of the given kind that are currently in the editing store
|
* Provides a collection of index paths for nodes of the given kind that are currently in the editing store
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -334,6 +334,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
[self performEditCommandWithBlock:^{
|
[self performEditCommandWithBlock:^{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
[self accessDataSourceWithBlock:^{
|
[self accessDataSourceWithBlock:^{
|
||||||
|
[self willPerformInitialDataLoading];
|
||||||
|
|
||||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||||
NSUInteger sectionNum = [_dataSource numberOfSectionsInDataController:self];
|
NSUInteger sectionNum = [_dataSource numberOfSectionsInDataController:self];
|
||||||
|
|
||||||
@@ -404,6 +406,13 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Initial & Reload Data Hooks (Subclass API)
|
||||||
|
|
||||||
|
- (void)willPerformInitialDataLoading
|
||||||
|
{
|
||||||
|
// Implemented by subclasses
|
||||||
|
}
|
||||||
|
|
||||||
- (void)prepareForReloadData
|
- (void)prepareForReloadData
|
||||||
{
|
{
|
||||||
// Implemented by subclasses
|
// Implemented by subclasses
|
||||||
@@ -538,7 +547,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
|
|
||||||
#pragma mark - Section Editing (External API)
|
#pragma mark - Section Editing (External API)
|
||||||
|
|
||||||
- (void)insertSections:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
- (void)insertSections:(NSIndexSet *)sections withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
||||||
{
|
{
|
||||||
[self performEditCommandWithBlock:^{
|
[self performEditCommandWithBlock:^{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
@@ -546,41 +555,47 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
||||||
|
|
||||||
[self accessDataSourceWithBlock:^{
|
[self accessDataSourceWithBlock:^{
|
||||||
|
[self prepareInsertSections:sections];
|
||||||
|
|
||||||
NSMutableArray *updatedNodes = [NSMutableArray array];
|
NSMutableArray *updatedNodes = [NSMutableArray array];
|
||||||
NSMutableArray *updatedIndexPaths = [NSMutableArray array];
|
NSMutableArray *updatedIndexPaths = [NSMutableArray array];
|
||||||
[self _populateFromDataSourceWithSectionIndexSet:indexSet mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths];
|
[self _populateFromDataSourceWithSectionIndexSet:sections mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths];
|
||||||
|
|
||||||
// Measure nodes whose views are loaded before we leave the main thread
|
// Measure nodes whose views are loaded before we leave the main thread
|
||||||
[self _layoutNodesWithMainThreadAffinity:updatedNodes atIndexPaths:updatedIndexPaths];
|
[self _layoutNodesWithMainThreadAffinity:updatedNodes atIndexPaths:updatedIndexPaths];
|
||||||
|
|
||||||
[_editingTransactionQueue addOperationWithBlock:^{
|
[_editingTransactionQueue addOperationWithBlock:^{
|
||||||
|
[self willInsertSections:sections];
|
||||||
|
|
||||||
LOG(@"Edit Transaction - insertSections: %@", indexSet);
|
LOG(@"Edit Transaction - insertSections: %@", indexSet);
|
||||||
NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:indexSet.count];
|
NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:sections.count];
|
||||||
for (NSUInteger i = 0; i < indexSet.count; i++) {
|
for (NSUInteger i = 0; i < sections.count; i++) {
|
||||||
[sectionArray addObject:[NSMutableArray array]];
|
[sectionArray addObject:[NSMutableArray array]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self _insertSections:sectionArray atIndexSet:indexSet withAnimationOptions:animationOptions];
|
[self _insertSections:sectionArray atIndexSet:sections withAnimationOptions:animationOptions];
|
||||||
[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOptions];
|
[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOptions];
|
||||||
}];
|
}];
|
||||||
}];
|
}];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)deleteSections:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
- (void)deleteSections:(NSIndexSet *)sections withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
||||||
{
|
{
|
||||||
[self performEditCommandWithBlock:^{
|
[self performEditCommandWithBlock:^{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
LOG(@"Edit Command - deleteSections: %@", indexSet);
|
LOG(@"Edit Command - deleteSections: %@", sections);
|
||||||
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
||||||
|
|
||||||
[_editingTransactionQueue addOperationWithBlock:^{
|
[_editingTransactionQueue addOperationWithBlock:^{
|
||||||
|
[self willDeleteSections:sections];
|
||||||
|
|
||||||
// remove elements
|
// remove elements
|
||||||
LOG(@"Edit Transaction - deleteSections: %@", indexSet);
|
LOG(@"Edit Transaction - deleteSections: %@", sections);
|
||||||
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet(_editingNodes[ASDataControllerRowNodeKind], indexSet);
|
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet(_editingNodes[ASDataControllerRowNodeKind], sections);
|
||||||
|
|
||||||
[self _deleteNodesAtIndexPaths:indexPaths withAnimationOptions:animationOptions];
|
[self _deleteNodesAtIndexPaths:indexPaths withAnimationOptions:animationOptions];
|
||||||
[self _deleteSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions];
|
[self _deleteSectionsAtIndexSet:sections withAnimationOptions:animationOptions];
|
||||||
}];
|
}];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@@ -594,6 +609,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
||||||
|
|
||||||
[self accessDataSourceWithBlock:^{
|
[self accessDataSourceWithBlock:^{
|
||||||
|
[self prepareForReloadSections:sections];
|
||||||
|
|
||||||
NSMutableArray *updatedNodes = [NSMutableArray array];
|
NSMutableArray *updatedNodes = [NSMutableArray array];
|
||||||
NSMutableArray *updatedIndexPaths = [NSMutableArray array];
|
NSMutableArray *updatedIndexPaths = [NSMutableArray array];
|
||||||
[self _populateFromDataSourceWithSectionIndexSet:sections mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths];
|
[self _populateFromDataSourceWithSectionIndexSet:sections mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths];
|
||||||
@@ -628,6 +645,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
|
||||||
|
|
||||||
[_editingTransactionQueue addOperationWithBlock:^{
|
[_editingTransactionQueue addOperationWithBlock:^{
|
||||||
|
[self willMoveSection:section toSection:newSection];
|
||||||
|
|
||||||
// remove elements
|
// remove elements
|
||||||
|
|
||||||
LOG(@"Edit Transaction - moveSection");
|
LOG(@"Edit Transaction - moveSection");
|
||||||
@@ -649,6 +668,38 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Section Insertion Hooks (Subclass API)
|
||||||
|
|
||||||
|
- (void)prepareInsertSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willInsertSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willDeleteSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)prepareForReloadSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willReloadSections:(NSIndexSet *)sections
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
|
||||||
|
{
|
||||||
|
// Implemented by subclass
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Row Editing (External API)
|
#pragma mark - Row Editing (External API)
|
||||||
|
|
||||||
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
|
||||||
|
|||||||
Reference in New Issue
Block a user