Skip to content

Commit 2956c0c

Browse files
leviLevi McCallum
authored andcommitted
Extract flow layout methods into a separate delegate
1 parent cefbcef commit 2956c0c

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

AsyncDisplayKit/ASCollectionView.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,34 @@
342342
*/
343343
- (BOOL)shouldBatchFetchForCollectionView:(ASCollectionView *)collectionView;
344344

345+
@end
346+
347+
@protocol ASCollectionViewDelegateFlowLayout <ASCollectionViewDelegate>
348+
349+
@optional
350+
345351
/**
346352
* Passthrough support to UICollectionViewDelegateFlowLayout sectionInset behavior.
347353
*
348354
* @param collectionView The sender.
349355
* @param collectionViewLayout The layout object requesting the information.
350-
* #param section The index number of the section whose insets are needed.
356+
* @param section The index number of the section whose insets are needed.
351357
*
352358
* @discussion The same rules apply as the UICollectionView implementation, but this can also be used without a UICollectionViewFlowLayout.
353359
* https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewDelegateFlowLayout_protocol/index.html#//apple_ref/occ/intfm/UICollectionViewDelegateFlowLayout/collectionView:layout:insetForSectionAtIndex:
354360
*
355361
*/
356-
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
362+
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
363+
364+
/**
365+
* Asks the delegate for the size of the header in the specified section.
366+
*/
367+
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
368+
369+
/**
370+
* Asks the delegate for the size of the footer in the specified section.
371+
*/
372+
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
357373

358374
@end
359375

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ - (ASSizeRange)dataController:(ASDataController *)dataController constrainedSize
628628
}
629629

630630
if (_asyncDelegateImplementsInsetSection) {
631-
sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section];
631+
sectionInset = [(id<ASCollectionViewDelegateFlowLayout>)_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section];
632632
}
633633

634634
if (ASScrollDirectionContainsHorizontalDirection([self scrollableDirections])) {

examples/ASCollectionView/Sample/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#import <AsyncDisplayKit/AsyncDisplayKit.h>
1515

16-
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegate>
16+
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
1717
{
1818
ASCollectionView *_collectionView;
1919
}
@@ -95,7 +95,7 @@ - (void)collectionView:(UICollectionView *)collectionView willBeginBatchFetchWit
9595
[context completeBatchFetching:YES];
9696
}
9797

98-
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
98+
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
9999
return UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0);
100100
}
101101

0 commit comments

Comments
 (0)