Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASCollectionView] Add strong Layer Pointer Under iOS < 9 to Workaround Crashes #1861

Merged
merged 1 commit into from
Jul 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe

ASCollectionViewInvalidationStyle _nextLayoutInvalidationStyle;

/**
* Our layer, retained. Under iOS < 9, when collection views are removed from the hierarchy,
* their layers may be deallocated and become dangling pointers. This puts the collection view
* into a very dangerous state where pretty much any call will crash it. So we manually retain our layer.
*
* You should never access this, and it will be nil under iOS >= 9.
*/
CALayer *_retainedLayer;

/**
* If YES, the `UICollectionView` will reload its data on next layout pass so we should not forward any updates to it.

Expand Down Expand Up @@ -248,6 +257,10 @@ - (instancetype)_initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionV

[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kCellReuseIdentifier];

if (!AS_AT_LEAST_IOS9) {
_retainedLayer = self.layer;
}

return self;
}

Expand Down