From d59c2661087fc6ff43344a5277fae014c45f5c0b Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Tue, 7 Jul 2020 07:24:28 -0700 Subject: [PATCH] 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 --- Source/IGListKit/IGListAdapterUpdater.m | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Source/IGListKit/IGListAdapterUpdater.m b/Source/IGListKit/IGListAdapterUpdater.m index e84e4228..b0d96e15 100644 --- a/Source/IGListKit/IGListAdapterUpdater.m +++ b/Source/IGListKit/IGListAdapterUpdater.m @@ -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> *_Nullable oldArray, NSArray> *_Nullable newArray,