From 4f4a26d2a3a61ce96a0cc66f853afe78610f4fab Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 12 Aug 2015 11:33:40 -0700 Subject: [PATCH 1/2] ASDK now supports non-flow layouts. We shouldn't be assuming a flow layout. --- AsyncDisplayKit/ASCollectionView.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index b19d41c355..47fba0de35 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -553,7 +553,10 @@ static BOOL _isInterceptedSelector(SEL sel) - (CGSize)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath { CGSize restrainedSize = self.bounds.size; - UIEdgeInsets sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset]; + UIEdgeInsets sectionInset = UIEdgeInsetsZero; + if ([self.collectionViewLayout respondsToSelector:@selector(sectionInset)]) { + sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset]; + } if (_implementsInsetSection) { sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section]; From 592e0301dd8c2ceb2ba264a1ca0db70170c0dbef Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 12 Aug 2015 11:46:46 -0700 Subject: [PATCH 2/2] cache result of responds to selector --- AsyncDisplayKit/ASCollectionView.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 47fba0de35..71bd52b010 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -119,7 +119,8 @@ static BOOL _isInterceptedSelector(SEL sel) NSMutableArray *_batchUpdateBlocks; BOOL _asyncDataFetchingEnabled; - BOOL _implementsInsetSection; + BOOL _asyncDelegateImplementsInsetSection; + BOOL _collectionViewLayoutImplementsInsetSection; ASBatchContext *_batchContext; @@ -175,6 +176,8 @@ static BOOL _isInterceptedSelector(SEL sel) [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil]; } + + _collectionViewLayoutImplementsInsetSection = [layout respondsToSelector:@selector(sectionInset)]; return self; } @@ -255,12 +258,12 @@ static BOOL _isInterceptedSelector(SEL sel) super.delegate = nil; _asyncDelegate = nil; _proxyDelegate = nil; - _implementsInsetSection = NO; + _asyncDelegateImplementsInsetSection = NO; } else { _asyncDelegate = asyncDelegate; _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; super.delegate = (id)_proxyDelegate; - _implementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0); + _asyncDelegateImplementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0); } } @@ -554,11 +557,11 @@ static BOOL _isInterceptedSelector(SEL sel) { CGSize restrainedSize = self.bounds.size; UIEdgeInsets sectionInset = UIEdgeInsetsZero; - if ([self.collectionViewLayout respondsToSelector:@selector(sectionInset)]) { + if (_collectionViewLayoutImplementsInsetSection) { sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset]; } - if (_implementsInsetSection) { + if (_asyncDelegateImplementsInsetSection) { sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section]; }