mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
fix inserting sections bug
This commit is contained in:
@@ -57,8 +57,8 @@
|
||||
/**
|
||||
Called for insertion of sections.
|
||||
*/
|
||||
- (void)dataController:(ASDataController *)dataController willInsertSectionsAtIndexSet:(NSIndexSet *)indexSet;
|
||||
- (void)dataController:(ASDataController *)dataController didInsertSectionsAtIndexSet:(NSIndexSet *)indexSet;
|
||||
- (void)dataController:(ASDataController *)dataController willInsertSections:(NSArray *)sections atIndexSet:(NSIndexSet *)indexSet;
|
||||
- (void)dataController:(ASDataController *)dataController didInsertSections:(NSArray *)sections atIndexSet:(NSIndexSet *)indexSet;
|
||||
|
||||
/**
|
||||
Called for deletion of sections.
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
|
||||
#define INSERT_SECTIONS(multidimensionalArray, indexSet, sections) \
|
||||
{ \
|
||||
if ([_delegate respondsToSelector:@selector(dataController:willInsertSectionsAtIndexSet:)]) { \
|
||||
[_delegate dataController:self willInsertSectionsAtIndexSet:indexSet]; \
|
||||
if ([_delegate respondsToSelector:@selector(dataController:willInsertSections:atIndexSet:)]) { \
|
||||
[_delegate dataController:self willInsertSections:sections atIndexSet:indexSet]; \
|
||||
} \
|
||||
[multidimensionalArray insertObjects:sections atIndexes:indexSet]; \
|
||||
if ([_delegate respondsToSelector:@selector(dataController:didInsertSectionsAtIndexSet:)]) { \
|
||||
[_delegate dataController:self didInsertSectionsAtIndexSet:indexSet]; \
|
||||
if ([_delegate respondsToSelector:@selector(dataController:didInsertSections:atIndexSet:)]) { \
|
||||
[_delegate dataController:self didInsertSections:sections atIndexSet:indexSet]; \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -206,8 +206,15 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext;
|
||||
|
||||
- (void)insertSections:(NSIndexSet *)indexSet {
|
||||
NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithCapacity:indexSet.count];
|
||||
for (int i = 0; i < indexSet.count; i++) {
|
||||
[sectionArray addObject:[[NSMutableArray alloc] init]];
|
||||
for (NSUInteger i = 0; i < indexSet.count; i++) {
|
||||
NSUInteger rowNum = [_dataSource dataController:self rowsInSection:i];
|
||||
NSMutableArray *rows = [[NSMutableArray alloc] initWithCapacity:rowNum];
|
||||
|
||||
for (NSUInteger j = 0; j < rowNum; j++) {
|
||||
ASCellNode *node = [_dataSource dataController:self nodeAtIndexPath:[NSIndexPath indexPathForItem:j inSection:i]];
|
||||
[rows addObject:node];
|
||||
}
|
||||
[sectionArray addObject:rows];
|
||||
}
|
||||
|
||||
dispatch_async([[self class] sizingQueue], ^{
|
||||
|
||||
@@ -53,9 +53,17 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)insertSectionsAtIndexSet:(NSIndexSet *)indexSet {
|
||||
- (void)insertSections:(NSArray *)sections atIndexSet:(NSIndexSet *)indexSet {
|
||||
__block int cnt = 0;
|
||||
[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
|
||||
_nodeSizes.insert(_nodeSizes.begin() + idx, std::vector<CGSize>());
|
||||
NSArray *nodes = sections[cnt++];
|
||||
std::vector<CGSize> v(nodes.count);
|
||||
|
||||
for (int i = 0; i < nodes.count; i++) {
|
||||
v.push_back([nodes[i] CGSizeValue]);
|
||||
}
|
||||
|
||||
_nodeSizes.insert(_nodeSizes.begin() + idx, v);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, ASScrollDirection) {
|
||||
|
||||
- (void)deleteNodesAtIndexPaths:(NSArray *)indexPaths;
|
||||
|
||||
- (void)insertSectionsAtIndexSet:(NSIndexSet *)indexSet;
|
||||
- (void)insertSections:(NSArray *)sections atIndexSet:(NSIndexSet *)indexSet;
|
||||
|
||||
- (void)deleteSectionsAtIndexSet:(NSIndexSet *)indexSet;
|
||||
|
||||
|
||||
@@ -245,9 +245,21 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)dataController:(ASDataController *)dataController didInsertSectionsAtIndexSet:(NSIndexSet *)indexSet {
|
||||
- (void)dataController:(ASDataController *)dataController didInsertSections:(NSArray *)sections atIndexSet:(NSIndexSet *)indexSet {
|
||||
ASDisplayNodeAssert(sections.count == indexSet.count, @"Invalid sections");
|
||||
|
||||
NSMutableArray *sectionNodeSizes = [NSMutableArray arrayWithCapacity:sections.count];
|
||||
|
||||
[sections enumerateObjectsUsingBlock:^(NSArray *nodes, NSUInteger idx, BOOL *stop) {
|
||||
NSMutableArray *nodeSizes = [NSMutableArray arrayWithCapacity:nodes.count];
|
||||
[nodes enumerateObjectsUsingBlock:^(ASCellNode *node, NSUInteger idx, BOOL *stop) {
|
||||
[nodeSizes addObject:[NSValue valueWithCGSize:node.calculatedSize]];
|
||||
}];
|
||||
[sectionNodeSizes addObject:nodeSizes];
|
||||
}];
|
||||
|
||||
[self updateOnMainThreadWithBlock:^{
|
||||
[_layoutController insertSectionsAtIndexSet:indexSet];
|
||||
[_layoutController insertSections:sectionNodeSizes atIndexSet:indexSet];
|
||||
[_delegate rangeController:self didInsertSectionsAtIndexSet:indexSet];
|
||||
}];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user