Skip to content

Commit af9f8df

Browse files
committed
Merge pull request facebookarchive#931 from lappp9/cells-with-view-controllers
[ASCellNode] Support for wrapping UIViewControllers
2 parents 676a1d3 + 322caae commit af9f8df

55 files changed

Lines changed: 1587 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@
15231523
058D09B9195D04C000B7D73C /* Frameworks */,
15241524
058D09BA195D04C000B7D73C /* Resources */,
15251525
3B9D88CDF51B429C8409E4B6 /* Copy Pods Resources */,
1526+
1B86F48711505F91D5FEF571 /* Embed Pods Frameworks */,
15261527
);
15271528
buildRules = (
15281529
);
@@ -1622,6 +1623,21 @@
16221623
/* End PBXResourcesBuildPhase section */
16231624

16241625
/* Begin PBXShellScriptBuildPhase section */
1626+
1B86F48711505F91D5FEF571 /* Embed Pods Frameworks */ = {
1627+
isa = PBXShellScriptBuildPhase;
1628+
buildActionMask = 2147483647;
1629+
files = (
1630+
);
1631+
inputPaths = (
1632+
);
1633+
name = "Embed Pods Frameworks";
1634+
outputPaths = (
1635+
);
1636+
runOnlyForDeploymentPostprocessing = 0;
1637+
shellPath = /bin/sh;
1638+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-frameworks.sh\"\n";
1639+
showEnvVarsInLog = 0;
1640+
};
16251641
2E61B6A0DB0F436A9DDBE86F /* Check Pods Manifest.lock */ = {
16261642
isa = PBXShellScriptBuildPhase;
16271643
buildActionMask = 2147483647;

AsyncDisplayKit/ASCellNode.h

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

96+
/**
97+
* @abstract Initializes a cell with a given viewControllerBlock.
98+
*
99+
* @param viewBlock The block that will be used to create the backing view.
100+
* @param didLoadBlock The block that will be called after the view created by the viewBlock is loaded
101+
*
102+
* @return An ASCellNode created using the root view of the view controller provided by the viewControllerBlock.
103+
* The view controller's root view is resized to match the calcuated size produced during layout.
104+
*
105+
*/
106+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
107+
96108
@end
97109

98110

AsyncDisplayKit/ASCellNode.m

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
#pragma mark -
1919
#pragma mark ASCellNode
2020

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

2332
- (instancetype)init
@@ -32,6 +41,49 @@ - (instancetype)init
3241
return self;
3342
}
3443

44+
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
45+
{
46+
if (!(self = [super init]))
47+
return nil;
48+
49+
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
50+
51+
if (viewControllerBlock) {
52+
_viewController = viewControllerBlock();
53+
54+
__weak UIViewController *weakViewController = _viewController;
55+
_viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
56+
return weakViewController.view;
57+
} didLoadBlock:didLoadBlock];
58+
59+
[self addSubnode:_viewControllerNode];
60+
_nodeLoadedBlock = didLoadBlock;
61+
}
62+
63+
return self;
64+
}
65+
66+
//- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
67+
//{
68+
// _viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max};
69+
// NSLog(@"%f %f", constrainedSize.max.width, constrainedSize.max.height);
70+
// return [super layoutSpecThatFits:constrainedSize];
71+
//}
72+
73+
- (void)layout
74+
{
75+
[super layout];
76+
77+
_viewControllerNode.frame = self.bounds;
78+
}
79+
80+
- (void)layoutDidFinish
81+
{
82+
[super layoutDidFinish];
83+
84+
_viewControllerNode.frame = self.bounds;
85+
}
86+
3587
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
3688
{
3789
ASDisplayNodeAssertNotSupported();
@@ -98,7 +150,8 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
98150
#pragma mark -
99151
#pragma mark ASTextCellNode
100152

101-
@interface ASTextCellNode () {
153+
@interface ASTextCellNode ()
154+
{
102155
NSString *_text;
103156
ASTextNode *_textNode;
104157
}

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
*/
2323
typedef UIView *(^ASDisplayNodeViewBlock)();
2424

25+
/**
26+
* UIView creation block. Used to create the backing view of a new display node.
27+
*/
28+
typedef UIViewController *(^ASDisplayNodeViewControllerBlock)();
29+
2530
/**
2631
* CALayer creation block. Used to create the backing layer of a new display node.
2732
*/

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
140140
overrides |= ASDisplayNodeMethodOverrideLayoutSpecThatFits;
141141
}
142142

143-
144143
return overrides;
145144
}
146145

@@ -294,7 +293,6 @@ - (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDispla
294293
return self;
295294
}
296295

297-
298296
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
299297
{
300298
return [self initWithLayerBlock:layerBlock didLoadBlock:nil];
@@ -316,7 +314,6 @@ - (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock didLoadBlock:(ASDis
316314
return self;
317315
}
318316

319-
320317
- (void)dealloc
321318
{
322319
ASDisplayNodeAssertMainThread();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://github.com/CocoaPods/Specs.git'
2+
platform :ios, '8.0'
3+
pod 'AsyncDisplayKit', :path => '../..'

0 commit comments

Comments
 (0)