Merge pull request #604 from garrettmoon/fixCrashForNonFlowLayout

Don't assume flow layout when checking for insetSections
This commit is contained in:
appleguy 2015-08-12 12:26:20 -07:00
commit 356ea9dc7f

View File

@ -119,7 +119,8 @@ static BOOL _isInterceptedSelector(SEL sel)
NSMutableArray *_batchUpdateBlocks; NSMutableArray *_batchUpdateBlocks;
BOOL _asyncDataFetchingEnabled; BOOL _asyncDataFetchingEnabled;
BOOL _implementsInsetSection; BOOL _asyncDelegateImplementsInsetSection;
BOOL _collectionViewLayoutImplementsInsetSection;
ASBatchContext *_batchContext; ASBatchContext *_batchContext;
@ -176,6 +177,8 @@ static BOOL _isInterceptedSelector(SEL sel)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
} }
_collectionViewLayoutImplementsInsetSection = [layout respondsToSelector:@selector(sectionInset)];
return self; return self;
} }
@ -255,12 +258,12 @@ static BOOL _isInterceptedSelector(SEL sel)
super.delegate = nil; super.delegate = nil;
_asyncDelegate = nil; _asyncDelegate = nil;
_proxyDelegate = nil; _proxyDelegate = nil;
_implementsInsetSection = NO; _asyncDelegateImplementsInsetSection = NO;
} else { } else {
_asyncDelegate = asyncDelegate; _asyncDelegate = asyncDelegate;
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self];
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate; super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
_implementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0); _asyncDelegateImplementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0);
} }
} }
@ -553,9 +556,12 @@ static BOOL _isInterceptedSelector(SEL sel)
- (CGSize)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath - (CGSize)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
{ {
CGSize restrainedSize = self.bounds.size; CGSize restrainedSize = self.bounds.size;
UIEdgeInsets sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset]; UIEdgeInsets sectionInset = UIEdgeInsetsZero;
if (_collectionViewLayoutImplementsInsetSection) {
sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset];
}
if (_implementsInsetSection) { if (_asyncDelegateImplementsInsetSection) {
sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section]; sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section];
} }