Swiftgram/AsyncDisplayKit/Layout/ASCompositeNode.mm
Huy Nguyen f8531f467d Add Layout nodes.
- The code is forked from LayoutComponents in ComponentKit.
- Public interfaces are modified to be strictly Objective-C. As a result, users are not forced to switch to Objective-C++, the linker can happily compile and Swift fans can continue using the mighty ASDK.
2015-06-25 11:32:30 +07:00

48 lines
1.2 KiB
Plaintext

/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#import "ASCompositeNode.h"
#import "ASBaseDefines.h"
#import "ASDisplayNode.h"
#import "ASLayoutNodeSubclass.h"
@implementation ASCompositeNode
+ (instancetype)newWithDisplayNode:(ASDisplayNode *)displayNode
{
return [self newWithSize:ASLayoutNodeSizeZero displayNode:displayNode];
}
+ (instancetype)newWithSize:(ASLayoutNodeSize)size displayNode:(ASDisplayNode *)displayNode
{
if (displayNode == nil) {
return nil;
}
ASCompositeNode *n = [super newWithSize:size];
if (n) {
n->_displayNode = displayNode;
}
return n;
}
+ (instancetype)newWithSize:(ASLayoutNodeSize)size
{
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
}
- (ASLayout *)computeLayoutThatFits:(ASSizeRange)constrainedSize
{
CGSize measuredSize = ASSizeRangeClamp(constrainedSize, [_displayNode measure:constrainedSize.max]);
return [ASLayout newWithNode:self size:measuredSize];
}
@end