[Examples] 2.0 Collection/Table API updates (#2390)

* update VerticalWithinHorizontal example

* update SocialAppLayout

* update Kittens

* update HorizontalWithinVerticalScrolling

* update AsyncDisplayKitOverview

* update CustomCollectionView

* CatDealsCollectionView

* update Swift

* address @appleguy's comment

* updates for tableNode deselectRowAtIndexPath
This commit is contained in:
Hannah Troisi
2016-10-24 17:14:28 -07:00
committed by Adlai Holler
parent 0d439a43b6
commit 0b7dfcc54d
17 changed files with 275 additions and 288 deletions

View File

@@ -39,6 +39,8 @@ static const CGFloat kInnerPadding = 10.0f;
@implementation HorizontalScrollCellNode
#pragma mark - Lifecycle
- (instancetype)initWithElementSize:(CGSize)size
{
if (!(self = [super init]))
@@ -46,11 +48,16 @@ static const CGFloat kInnerPadding = 10.0f;
_elementSize = size;
// the containing table uses -nodeForRowAtIndexPath (rather than -nodeBlockForRowAtIndexPath),
// so this init method will always be run on the main thread (thus it is safe to do UIKit things).
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize = _elementSize;
flowLayout.minimumInteritemSpacing = kInnerPadding;
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:flowLayout];
_collectionNode.delegate = self;
_collectionNode.dataSource = self;
[self addSubnode:_collectionNode];
// hairline cell separator
@@ -61,40 +68,6 @@ static const CGFloat kInnerPadding = 10.0f;
return self;
}
- (void)didLoad
{
[super didLoad];
_collectionNode.view.asyncDelegate = self;
_collectionNode.view.asyncDataSource = self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 5;
}
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize elementSize = _elementSize;
return ^{
RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init];
elementNode.style.preferredSize = elementSize;
return elementNode;
};
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
CGSize collectionNodeSize = CGSizeMake(constrainedSize.max.width, _elementSize.height);
_collectionNode.style.preferredSize = collectionNodeSize;
ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, 0.0, kOuterPadding, 0.0);
insetSpec.child = _collectionNode;
return insetSpec;
}
// With box model, you don't need to override this method, unless you want to add custom logic.
- (void)layout
{
@@ -107,4 +80,34 @@ static const CGFloat kInnerPadding = 10.0f;
_divider.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, pixelHeight);
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
CGSize collectionNodeSize = CGSizeMake(constrainedSize.max.width, _elementSize.height);
_collectionNode.style.preferredSize = collectionNodeSize;
ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, 0.0, kOuterPadding, 0.0);
insetSpec.child = _collectionNode;
return insetSpec;
}
#pragma mark - ASCollectionNode
- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section
{
return 5;
}
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize elementSize = _elementSize;
return ^{
RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init];
elementNode.style.preferredSize = elementSize;
return elementNode;
};
}
@end