Skip to content

Commit ed63577

Browse files
committed
Merge pull request facebookarchive#789 from Adlai-Holler/FixAnimationEnabledness
Avoid overwriting areAnimationsEnabled if app changes it again during animation
2 parents f11b6ac + cf8946c commit ed63577

3 files changed

Lines changed: 26 additions & 40 deletions

File tree

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -789,26 +789,14 @@ - (void)rangeController:(ASRangeController *)rangeController endUpdatesAnimated:
789789
}
790790
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
791791
}
792-
793-
BOOL animationsEnabled = NO;
794-
795-
if (!animated) {
796-
animationsEnabled = [UIView areAnimationsEnabled];
797-
[UIView setAnimationsEnabled:NO];
798-
}
799-
800-
[super performBatchUpdates:^{
801-
[_batchUpdateBlocks enumerateObjectsUsingBlock:^(dispatch_block_t block, NSUInteger idx, BOOL *stop) {
802-
block();
803-
}];
804-
} completion:^(BOOL finished) {
805-
if (!animated) {
806-
[UIView setAnimationsEnabled:animationsEnabled];
807-
}
808-
if (completion) {
809-
completion(finished);
810-
}
811-
}];
792+
793+
ASPerformBlockWithoutAnimation(!animated, ^{
794+
[super performBatchUpdates:^{
795+
for (dispatch_block_t block in _batchUpdateBlocks) {
796+
block();
797+
}
798+
} completion:completion];
799+
});
812800

813801
[_batchUpdateBlocks removeAllObjects];
814802
_performingBatchUpdates = NO;

AsyncDisplayKit/ASTableView.mm

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,6 @@ @interface ASTableView () <ASRangeControllerDelegate, ASDataControllerSource, _A
180180

181181
@implementation ASTableView
182182

183-
/**
184-
@summary Conditionally performs UIView geometry changes in the given block without animation.
185-
186-
Used primarily to circumvent UITableView forcing insertion animations when explicitly told not to via
187-
`UITableViewRowAnimationNone`. More info: https://github.com/facebook/AsyncDisplayKit/pull/445
188-
189-
@param withoutAnimation Set to `YES` to perform given block without animation
190-
@param block Perform UIView geometry changes within the passed block
191-
*/
192-
void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
193-
if (withoutAnimation) {
194-
BOOL animationsEnabled = [UIView areAnimationsEnabled];
195-
[UIView setAnimationsEnabled:NO];
196-
block();
197-
[UIView setAnimationsEnabled:animationsEnabled];
198-
} else {
199-
block();
200-
}
201-
}
202-
203183
+ (Class)dataControllerClass
204184
{
205185
return [ASChangeSetDataController class];

AsyncDisplayKit/Private/ASInternalHelpers.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CoreGraphics/CGBase.h>
1212
#import <Foundation/Foundation.h>
13+
#import <UIKit/UIKit.h>
1314
#import "ASBaseDefines.h"
1415

1516
ASDISPLAYNODE_EXTERN_C_BEGIN
@@ -27,6 +28,23 @@ CGFloat ASRoundPixelValue(CGFloat f);
2728

2829
ASDISPLAYNODE_EXTERN_C_END
2930

31+
/**
32+
@summary Conditionally performs UIView geometry changes in the given block without animation.
33+
34+
Used primarily to circumvent UITableView forcing insertion animations when explicitly told not to via
35+
`UITableViewRowAnimationNone`. More info: https://github.com/facebook/AsyncDisplayKit/pull/445
36+
37+
@param withoutAnimation Set to `YES` to perform given block without animation
38+
@param block Perform UIView geometry changes within the passed block
39+
*/
40+
ASDISPLAYNODE_INLINE void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
41+
if (withoutAnimation) {
42+
[UIView performWithoutAnimation:block];
43+
} else {
44+
block();
45+
}
46+
}
47+
3048
@interface NSIndexPath (ASInverseComparison)
3149
- (NSComparisonResult)asdk_inverseCompare:(NSIndexPath *)otherIndexPath;
3250
@end

0 commit comments

Comments
 (0)