-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[ASCollectionView / ASTableView] Optimize reloadData and reloadSection: methods. #1171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,10 +303,7 @@ - (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy | |
|
||
- (void)reloadDataWithCompletion:(void (^)())completion | ||
{ | ||
ASPerformBlockOnMainThread(^{ | ||
[super reloadData]; | ||
}); | ||
[_dataController reloadDataWithAnimationOptions:UITableViewRowAnimationNone completion:completion]; | ||
[_dataController reloadDataWithCompletion:completion]; | ||
} | ||
|
||
- (void)reloadData | ||
|
@@ -317,8 +314,7 @@ - (void)reloadData | |
- (void)reloadDataImmediately | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
[_dataController reloadDataImmediatelyWithAnimationOptions:UITableViewRowAnimationNone]; | ||
[super reloadData]; | ||
[_dataController reloadDataImmediately]; | ||
} | ||
|
||
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType | ||
|
@@ -433,7 +429,7 @@ - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAn | |
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
[_dataController moveSection:section toSection:newSection withAnimationOptions:UITableViewRowAnimationNone]; | ||
[_dataController moveSection:section toSection:newSection]; | ||
} | ||
|
||
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation | ||
|
@@ -457,7 +453,7 @@ - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableVi | |
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
[_dataController moveRowAtIndexPath:indexPath toIndexPath:newIndexPath withAnimationOptions:UITableViewRowAnimationNone]; | ||
[_dataController moveRowAtIndexPath:indexPath toIndexPath:newIndexPath]; | ||
} | ||
|
||
#pragma mark - | ||
|
@@ -834,6 +830,36 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteNodes:(NSA | |
} | ||
} | ||
|
||
- (void)rangeController:(ASRangeController *)rangeController didReloadNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
LOG(@"UITableView reloadRows:%ld rows", indexPaths.count); | ||
|
||
if (!self.asyncDataSource) { | ||
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes | ||
} | ||
|
||
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone; | ||
ASPerformBlockWithoutAnimation(preventAnimation, ^{ | ||
[super reloadRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOptions]; | ||
}); | ||
|
||
if (_automaticallyAdjustsContentOffset) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what is the policy to adjust content offset? It is done after reloading nodes, but not sections or everything/data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nguyenhuy @lkzhao I think we should honor it wherever it can be reasonably accommodated, especially inserting and deleting elements, as well as moving or reloading individual items and sections as that may cause them to calculate a different height. I think the main challenge with doing it on a full table reload at the moment is that we break it into a delete and insert, At least historically, and because of the asynchronous delay of the insert it was not always feasible to guarantee. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it is feasible thanks to this awesome diff. Let's do it then! |
||
[self adjustContentOffsetWithNodes:nodes atIndexPaths:indexPaths inserting:YES]; | ||
} | ||
} | ||
|
||
- (void)rangeController:(ASRangeController *)rangeController didMoveNodeAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
|
||
if (!self.asyncDataSource) { | ||
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes | ||
} | ||
|
||
[self moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; | ||
} | ||
|
||
- (void)rangeController:(ASRangeController *)rangeController didInsertSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
|
@@ -850,6 +876,36 @@ - (void)rangeController:(ASRangeController *)rangeController didInsertSectionsAt | |
}); | ||
} | ||
|
||
- (void)rangeController:(ASRangeController *)rangeController didReloadSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
LOG(@"UITableView reloadSections:%@", indexSet); | ||
|
||
|
||
if (!self.asyncDataSource) { | ||
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes | ||
} | ||
|
||
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone; | ||
ASPerformBlockWithoutAnimation(preventAnimation, ^{ | ||
[super reloadSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOptions]; | ||
}); | ||
} | ||
|
||
- (void)rangeController:(ASRangeController *)rangeController didMoveSection:(NSInteger)fromIndex toSection:(NSInteger)toIndex | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
LOG(@"UITableView moveSection:%@", indexSet); | ||
|
||
|
||
if (!self.asyncDataSource) { | ||
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes | ||
} | ||
|
||
[super moveSection:fromIndex toSection:toIndex]; | ||
} | ||
|
||
|
||
- (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
|
@@ -865,6 +921,17 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt | |
}); | ||
} | ||
|
||
- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController{ | ||
ASDisplayNodeAssertMainThread(); | ||
LOG(@"UITableView reloadData"); | ||
|
||
if (!self.asyncDataSource) { | ||
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes | ||
} | ||
|
||
[super reloadData]; | ||
} | ||
|
||
#pragma mark - ASDataControllerDelegate | ||
|
||
- (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAtIndexPath:(NSIndexPath *)indexPath { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to notify the
_layoutFacilitator
here? cc @binlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we will need to do