Clarify default value behavior of the layoutDelegate for flow layouts

This commit is contained in:
Levi McCallum 2015-10-11 11:28:01 -07:00
parent a9023dd400
commit ba72c73779
3 changed files with 25 additions and 7 deletions

View File

@ -228,7 +228,9 @@ static BOOL _isInterceptedSelector(SEL sel)
// Register the default layout inspector delegate for flow layouts, custom layouts
// will need to roll their own ASCollectionViewLayoutInspecting implementation.
_layoutDelegate = [self flowLayoutInspector];
if ([layout asdk_isFlowLayout]) {
_layoutDelegate = [self flowLayoutInspector];
}
_registeredSupplementaryKinds = [NSMutableArray array];
@ -249,8 +251,6 @@ static BOOL _isInterceptedSelector(SEL sel)
/**
* A layout inspector implementation specific for the sizing behavior of UICollectionViewFlowLayouts
*
* @discussion Will return nil if the current layout is not a flow layout
*/
- (ASCollectionViewFlowLayoutInspector *)flowLayoutInspector
{

View File

@ -21,11 +21,12 @@
- (instancetype)initWithCollectionView:(ASCollectionView *)collectionView flowLayout:(UICollectionViewFlowLayout *)flowLayout
{
self = [super init];
if (flowLayout == nil) {
return nil;
}
self = [super init];
if (self != nil) {
self.collectionView = collectionView;
_layout = flowLayout;

View File

@ -6,7 +6,8 @@
//
#import <XCTest/XCTest.h>
#import <AsyncDisplayKit/ASCollectionView.h>
#import "ASCollectionView.h"
#import "ASCollectionViewFlowLayoutInspector.h"
@interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate>
@ -79,7 +80,23 @@
@implementation ASCollectionViewTests
- (void)DISABLED_testCollectionViewController {
- (void)testThatItSetsALayoutInspectorForFlowLayouts
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
ASCollectionView *collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
XCTAssert(collectionView.layoutDelegate != nil, @"should automatically set a layout delegate for flow layouts");
XCTAssert([collectionView.layoutDelegate isKindOfClass:[ASCollectionViewFlowLayoutInspector class]], @"should have a flow layout inspector by default");
}
- (void)testThatItDoesNotSetALayoutInspectorForCustomLayouts
{
UICollectionViewLayout *layout = [[UICollectionViewLayout alloc] init];
ASCollectionView *collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts");
}
- (void)DISABLED_testCollectionViewController
{
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];