Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Commit

Permalink
Update GMGridViewController.m
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshflock authored Jun 19, 2018
1 parent 5ee98e8 commit d9352d1
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions GMImagePicker/GMGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -495,45 +495,15 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe

- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// Call might come on any background queue. Re-dispatch to the main queue to handle it.
// Removing animations as providing animations sometimes triggred a crash
// http://crashes.to/s/a870db76edc
// Though people claim a fix here
// https://stackoverflow.com/questions/29337765/crash-attempt-to-delete-and-reload-the-same-index-path
// but it seems not a 100% fix, hence going forward with simplicity of a reload
dispatch_async(dispatch_get_main_queue(), ^{

// check if there are changes to the assets (insertions, deletions, updates)
PHFetchResultChangeDetails *collectionChanges = [changeInstance changeDetailsForFetchResult:self.assetsFetchResults];
if (collectionChanges) {

// get the new fetch result
self.assetsFetchResults = [collectionChanges fetchResultAfterChanges];

UICollectionView *collectionView = self.collectionView;

if (![collectionChanges hasIncrementalChanges] || [collectionChanges hasMoves]) {
// we need to reload all if the incremental diffs are not available
[collectionView reloadData];

} else {
// if we have incremental diffs, tell the collection view to animate insertions and deletions
[collectionView performBatchUpdates:^{
NSIndexSet *removedIndexes = [collectionChanges removedIndexes];
if ([removedIndexes count]) {
[collectionView deleteItemsAtIndexPaths:[removedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes];
if ([insertedIndexes count]) {
[collectionView insertItemsAtIndexPaths:[insertedIndexes aapl_indexPathsFromIndexesWithSection:0]];
if (self.picker.showCameraButton && self.picker.autoSelectCameraImages) {
for (NSIndexPath *path in [insertedIndexes aapl_indexPathsFromIndexesWithSection:0]) {
[self collectionView:collectionView didSelectItemAtIndexPath:path];
}
}
}
NSIndexSet *changedIndexes = [collectionChanges changedIndexes];
if ([changedIndexes count]) {
[collectionView reloadItemsAtIndexPaths:[changedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
} completion:NULL];
}

[self.collectionView reloadData];
[self resetCachedAssets];
}
});
Expand Down

0 comments on commit d9352d1

Please sign in to comment.