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
0 commit comments