Skip to content

Commit

Permalink
Prevent UITableView insertion/deletion animations by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi McCallum committed May 8, 2015
1 parent f248dbd commit 1530ef2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#import "ASDisplayNodeInternal.h"
#import "ASBatchFetching.h"

const static NSUInteger kASCollectionViewAnimationNone = 0;
const static NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone;


#pragma mark -
Expand Down
27 changes: 22 additions & 5 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ @interface ASTableView () <ASRangeControllerDelegate, ASDataControllerSource> {

@implementation ASTableView

void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
if (withoutAnimation) {
[UIView setAnimationsEnabled:NO];
block();
[UIView setAnimationsEnabled:YES];
} else {
block();
}
}

#pragma mark -
#pragma mark Lifecycle

Expand Down Expand Up @@ -467,29 +477,36 @@ - (CGSize)rangeControllerViewportSize:(ASRangeController *)rangeController
- (void)rangeController:(ASRangeController *)rangeController didInsertNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOption:(ASDataControllerAnimationOptions)animationOption
{
ASDisplayNodeAssertMainThread();

[super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];
ASPerformBlockWithoutAnimation(animationOption == UITableViewRowAnimationNone, ^{
[super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];
});
}

- (void)rangeController:(ASRangeController *)rangeController didDeleteNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOption:(ASDataControllerAnimationOptions)animationOption
{
ASDisplayNodeAssertMainThread();

[super deleteRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];
ASPerformBlockWithoutAnimation(animationOption == UITableViewRowAnimationNone, ^{
[super deleteRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];
});
}

- (void)rangeController:(ASRangeController *)rangeController didInsertSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOption:(ASDataControllerAnimationOptions)animationOption
{
ASDisplayNodeAssertMainThread();

[super insertSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOption];
ASPerformBlockWithoutAnimation(animationOption == UITableViewRowAnimationNone, ^{
[super insertSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOption];
});
}

- (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOption:(ASDataControllerAnimationOptions)animationOption
{
ASDisplayNodeAssertMainThread();

[super deleteSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOption];
ASPerformBlockWithoutAnimation(animationOption == UITableViewRowAnimationNone, ^{
[super deleteSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOption];
});
}

#pragma mark - ASDataControllerDelegate
Expand Down

0 comments on commit 1530ef2

Please sign in to comment.