view controller node is resized to match layoutspec for cells

This commit is contained in:
Luke Parham
2015-12-09 13:13:39 -06:00
parent 5e34f10b81
commit eeb49859f0
5 changed files with 67 additions and 28 deletions

View File

@@ -93,6 +93,15 @@ typedef NSUInteger ASCellNodeAnimation;
*/
- (void)setNeedsLayout;
/* TODO: WRITE DOCUMENTATION */
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
@end

View File

@@ -18,6 +18,13 @@
#pragma mark -
#pragma mark ASCellNode
@interface ASCellNode (){
ASDisplayNodeDidLoadBlock _nodeLoadedBlock;
ASDisplayNode *_viewControllerNode;
UIViewController *_viewController;
}
@end
@implementation ASCellNode
- (instancetype)init
@@ -32,6 +39,35 @@
return self;
}
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
{
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
}
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
if (!(self = [super init]))
return nil;
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
_viewController = viewControllerBlock();
_viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
return _viewController.view;
} didLoadBlock:didLoadBlock];
[self addSubnode:_viewControllerNode];
_nodeLoadedBlock = didLoadBlock; //not sure where i should plug in to call this...
return self;
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
_viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max};
return [super layoutSpecThatFits:constrainedSize];
}
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDisplayNodeAssertNotSupported();
@@ -40,9 +76,8 @@
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
return [super initWithViewBlock:viewBlock didLoadBlock:didLoadBlock];
// ASDisplayNodeAssertNotSupported();
// return nil;
ASDisplayNodeAssertNotSupported();
return nil;
}
- (void)setLayerBacked:(BOOL)layerBacked
@@ -70,6 +105,9 @@
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
[(_ASDisplayView *)self.view __forwardTouchesBegan:touches withEvent:event];
// if (_viewController) {
// [_viewController touchesBegan:touches withEvent:event];
// }
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
@@ -77,6 +115,9 @@
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
[(_ASDisplayView *)self.view __forwardTouchesMoved:touches withEvent:event];
// if (_viewController) {
// [_viewController touchesMoved:touches withEvent:event];
// }
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
@@ -84,6 +125,9 @@
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
[(_ASDisplayView *)self.view __forwardTouchesEnded:touches withEvent:event];
// if (_viewController) {
// [_viewController touchesEnded:touches withEvent:event];
// }
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
@@ -91,6 +135,9 @@
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
// if (_viewController) {
// [_viewController touchesCancelled:touches withEvent:event];
// }
}
@end

View File

@@ -98,10 +98,6 @@ typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
*/
- (id)init;
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
/**
* @abstract Alternative initializer with a block to create the backing view.
*

View File

@@ -251,25 +251,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
return self;
}
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
{
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
}
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
if (!(self = [super init]))
return nil;
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
return [self initWithViewBlock:^UIView *{
UIViewController *vc = viewControllerBlock();
vc.view.clipsToBounds = YES; // not sure this is the way to go, doesn't really make it better per se
return vc.view;
} didLoadBlock:didLoadBlock];
}
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
{
return [self initWithViewBlock:viewBlock didLoadBlock:nil];

View File

@@ -14,7 +14,7 @@
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "MosaicCollectionViewLayout.h"
#import "SupplementaryNode.h"
#import "ImageCellNode.h"
#import "ImageViewController.h"
static NSUInteger kNumberOfImages = 14;
@@ -92,7 +92,13 @@ static NSUInteger kNumberOfImages = 14;
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{
return [[ImageViewController alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
}];
return node;
//[[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
}
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath