avoid calling UICollectionView performBatch update directly from a block

Summary: Wrap `[UICollectionView performBatchUpdates ...]` so that in case it crashes, the first app symbol will not be a block. A block name includes the line number, which means if you change the block line number, it will be categorized as a different crash. This makes tracking crashes across multiple app-versions a pain.

Differential Revision: D22398750

fbshipit-source-id: 90643e7eafe76b07e7022111f183e4734fd8a347
This commit is contained in:
Maxime Ollivier 2020-07-07 07:24:28 -07:00 committed by Facebook GitHub Bot
parent c9e9a4b7d4
commit d59c266108

View file

@ -18,6 +18,8 @@
#import "UICollectionView+IGListBatchUpdateData.h"
typedef void (^IGListAdapterUpdaterDiffResultBlock)(IGListIndexSetResult *);
typedef void (^IGListAdapterUpdaterBlock)(void);
typedef void (^IGListAdapterUpdaterCompletionBlock)(BOOL);
@implementation IGListAdapterUpdater
@ -263,17 +265,13 @@ willPerformBatchUpdatesWithCollectionView:collectionView
toObjects:toObjects
listIndexSetResult:result
animated:animated];
if (animated) {
[collectionView performBatchUpdates:^{
batchUpdatesBlock(result);
} completion:batchUpdatesCompletionBlock];
} else {
[UIView performWithoutAnimation:^{
[collectionView performBatchUpdates:^{
batchUpdatesBlock(result);
} completion:batchUpdatesCompletionBlock];
}];
}
// Wrap `[UICollectionView performBatchUpdates ...]` so that in case it crashes, the first app symbol will not be a block. A block name includes the
// line number, which means if you change the block line number, it will be categorized as a different crash. This makes tracking crashes
// across multiple app-versions a pain.
IGListAdapterUpdaterPerformBatchUpdate(collectionView, animated, ^{
batchUpdatesBlock(result);
}, batchUpdatesCompletionBlock);
};
// block that executes the batch update and exception handling
@ -566,7 +564,17 @@ static NSUInteger IGListIdentifierHash(const void *item, NSUInteger (*size)(cons
}
}
#pragma mark - Diffing
#pragma mark - Helpers
static void IGListAdapterUpdaterPerformBatchUpdate(UICollectionView *collectionView, BOOL animated, IGListAdapterUpdaterBlock updates, IGListAdapterUpdaterCompletionBlock completion) {
if (animated) {
[collectionView performBatchUpdates:updates completion:completion];
} else {
[UIView performWithoutAnimation:^{
[collectionView performBatchUpdates:updates completion:completion];
}];
}
}
static void IGListAdapterUpdaterPerformDiffing(NSArray<id<IGListDiffable>> *_Nullable oldArray,
NSArray<id<IGListDiffable>> *_Nullable newArray,