Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit eeb4985

Browse files
committed
view controller node is resized to match layoutspec for cells
1 parent 5e34f10 commit eeb4985

5 files changed

Lines changed: 67 additions & 28 deletions

File tree

AsyncDisplayKit/ASCellNode.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ typedef NSUInteger ASCellNodeAnimation;
9393
*/
9494
- (void)setNeedsLayout;
9595

96+
97+
98+
/* TODO: WRITE DOCUMENTATION */
99+
100+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
101+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
102+
103+
104+
96105
@end
97106

98107

AsyncDisplayKit/ASCellNode.m

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
#pragma mark -
1919
#pragma mark ASCellNode
2020

21+
@interface ASCellNode (){
22+
ASDisplayNodeDidLoadBlock _nodeLoadedBlock;
23+
ASDisplayNode *_viewControllerNode;
24+
UIViewController *_viewController;
25+
}
26+
@end
27+
2128
@implementation ASCellNode
2229

2330
- (instancetype)init
@@ -32,6 +39,35 @@ - (instancetype)init
3239
return self;
3340
}
3441

42+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
43+
{
44+
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
45+
}
46+
47+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
48+
{
49+
if (!(self = [super init]))
50+
return nil;
51+
52+
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
53+
54+
_viewController = viewControllerBlock();
55+
_viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
56+
return _viewController.view;
57+
} didLoadBlock:didLoadBlock];
58+
59+
[self addSubnode:_viewControllerNode];
60+
61+
_nodeLoadedBlock = didLoadBlock; //not sure where i should plug in to call this...
62+
return self;
63+
}
64+
65+
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
66+
_viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max};
67+
68+
return [super layoutSpecThatFits:constrainedSize];
69+
}
70+
3571
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
3672
{
3773
ASDisplayNodeAssertNotSupported();
@@ -40,9 +76,8 @@ - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlo
4076

4177
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
4278
{
43-
return [super initWithViewBlock:viewBlock didLoadBlock:didLoadBlock];
44-
// ASDisplayNodeAssertNotSupported();
45-
// return nil;
79+
ASDisplayNodeAssertNotSupported();
80+
return nil;
4681
}
4782

4883
- (void)setLayerBacked:(BOOL)layerBacked
@@ -70,27 +105,39 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
70105
ASDisplayNodeAssertMainThread();
71106
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
72107
[(_ASDisplayView *)self.view __forwardTouchesBegan:touches withEvent:event];
108+
// if (_viewController) {
109+
// [_viewController touchesBegan:touches withEvent:event];
110+
// }
73111
}
74112

75113
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
76114
{
77115
ASDisplayNodeAssertMainThread();
78116
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
79117
[(_ASDisplayView *)self.view __forwardTouchesMoved:touches withEvent:event];
118+
// if (_viewController) {
119+
// [_viewController touchesMoved:touches withEvent:event];
120+
// }
80121
}
81122

82123
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
83124
{
84125
ASDisplayNodeAssertMainThread();
85126
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
86127
[(_ASDisplayView *)self.view __forwardTouchesEnded:touches withEvent:event];
128+
// if (_viewController) {
129+
// [_viewController touchesEnded:touches withEvent:event];
130+
// }
87131
}
88132

89133
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
90134
{
91135
ASDisplayNodeAssertMainThread();
92136
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
93137
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
138+
// if (_viewController) {
139+
// [_viewController touchesCancelled:touches withEvent:event];
140+
// }
94141
}
95142

96143
@end

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
9898
*/
9999
- (id)init;
100100

101-
102-
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
103-
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
104-
105101
/**
106102
* @abstract Alternative initializer with a block to create the backing view.
107103
*

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,6 @@ - (id)initWithLayerClass:(Class)layerClass
251251
return self;
252252
}
253253

254-
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
255-
{
256-
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
257-
}
258-
259-
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
260-
{
261-
if (!(self = [super init]))
262-
return nil;
263-
264-
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
265-
266-
return [self initWithViewBlock:^UIView *{
267-
UIViewController *vc = viewControllerBlock();
268-
vc.view.clipsToBounds = YES; // not sure this is the way to go, doesn't really make it better per se
269-
return vc.view;
270-
} didLoadBlock:didLoadBlock];
271-
}
272-
273254
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
274255
{
275256
return [self initWithViewBlock:viewBlock didLoadBlock:nil];

examples/CollectionViewWithViewControllerCells/Sample/ViewController.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#import <AsyncDisplayKit/AsyncDisplayKit.h>
1515
#import "MosaicCollectionViewLayout.h"
1616
#import "SupplementaryNode.h"
17-
#import "ImageCellNode.h"
17+
#import "ImageViewController.h"
1818

1919
static NSUInteger kNumberOfImages = 14;
2020

@@ -92,7 +92,13 @@ - (void)reloadTapped
9292

9393
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
9494
{
95-
return [[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
95+
ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{
96+
return [[ImageViewController alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
97+
}];
98+
99+
return node;
100+
101+
//[[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
96102
}
97103

98104
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

0 commit comments

Comments
 (0)