diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index c123914ab7..c964b89f3e 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -789,26 +789,14 @@ static BOOL _isInterceptedSelector(SEL sel) } return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes } - - BOOL animationsEnabled = NO; - - if (!animated) { - animationsEnabled = [UIView areAnimationsEnabled]; - [UIView setAnimationsEnabled:NO]; - } - - [super performBatchUpdates:^{ - [_batchUpdateBlocks enumerateObjectsUsingBlock:^(dispatch_block_t block, NSUInteger idx, BOOL *stop) { - block(); - }]; - } completion:^(BOOL finished) { - if (!animated) { - [UIView setAnimationsEnabled:animationsEnabled]; - } - if (completion) { - completion(finished); - } - }]; + + ASPerformBlockWithoutAnimation(!animated, ^{ + [super performBatchUpdates:^{ + for (dispatch_block_t block in _batchUpdateBlocks) { + block(); + } + } completion:completion]; + }); [_batchUpdateBlocks removeAllObjects]; _performingBatchUpdates = NO; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 6729242e9c..06991451e5 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -180,26 +180,6 @@ static BOOL _isInterceptedSelector(SEL sel) @implementation ASTableView -/** - @summary Conditionally performs UIView geometry changes in the given block without animation. - - Used primarily to circumvent UITableView forcing insertion animations when explicitly told not to via - `UITableViewRowAnimationNone`. More info: https://github.com/facebook/AsyncDisplayKit/pull/445 - - @param withoutAnimation Set to `YES` to perform given block without animation - @param block Perform UIView geometry changes within the passed block - */ -void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { - if (withoutAnimation) { - BOOL animationsEnabled = [UIView areAnimationsEnabled]; - [UIView setAnimationsEnabled:NO]; - block(); - [UIView setAnimationsEnabled:animationsEnabled]; - } else { - block(); - } -} - + (Class)dataControllerClass { return [ASChangeSetDataController class]; diff --git a/AsyncDisplayKit/Private/ASInternalHelpers.h b/AsyncDisplayKit/Private/ASInternalHelpers.h index 00bed4b1d6..dcd6b38b72 100644 --- a/AsyncDisplayKit/Private/ASInternalHelpers.h +++ b/AsyncDisplayKit/Private/ASInternalHelpers.h @@ -10,6 +10,7 @@ #include #import +#import #import "ASBaseDefines.h" ASDISPLAYNODE_EXTERN_C_BEGIN @@ -27,6 +28,23 @@ CGFloat ASRoundPixelValue(CGFloat f); ASDISPLAYNODE_EXTERN_C_END +/** + @summary Conditionally performs UIView geometry changes in the given block without animation. + + Used primarily to circumvent UITableView forcing insertion animations when explicitly told not to via + `UITableViewRowAnimationNone`. More info: https://github.com/facebook/AsyncDisplayKit/pull/445 + + @param withoutAnimation Set to `YES` to perform given block without animation + @param block Perform UIView geometry changes within the passed block + */ +ASDISPLAYNODE_INLINE void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { + if (withoutAnimation) { + [UIView performWithoutAnimation:block]; + } else { + block(); + } +} + @interface NSIndexPath (ASInverseComparison) - (NSComparisonResult)asdk_inverseCompare:(NSIndexPath *)otherIndexPath; @end