[Layout] Move [ASLayoutSpec children] from std::map to NSMutableArray (#2253)

* Initial commit to move [ASLayoutSpec children] from std::map to NSMutableArray

* Add NSFastEnumeration to ASLayoutable

* ASNullLayoutSpec is a Singleton now

* Move ASLayoutSpecPrivate in Private folder

* Move to NSArrayPointer and remove ASNullLayoutSpec

* Revert "Move to NSArrayPointer and remove ASNullLayoutSpec"

This reverts commit 9ab9cf7024b1f6e1984d84fe58af2b84e84cdf94.

* Move to childAtIndex: and setChild:atIndex:
This commit is contained in:
Michael Schneider
2016-09-27 16:41:45 -07:00
committed by Adlai Holler
parent 8a4d4e3b5c
commit 2f99951732
13 changed files with 341 additions and 154 deletions

View File

@@ -9,6 +9,7 @@
//
#import "ASOverlayLayoutSpec.h"
#import "ASLayoutSpec+Subclasses.h"
#import "ASAssert.h"
#import "ASLayout.h"
@@ -18,32 +19,40 @@ static NSUInteger const kOverlayChildIndex = 1;
@implementation ASOverlayLayoutSpec
- (instancetype)initWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
{
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child that will be overlayed on shouldn't be nil");
self.overlay = overlay;
[self setChild:child forIndex:kUnderlayChildIndex];
return self;
}
#pragma mark - Class
+ (instancetype)overlayLayoutSpecWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
{
return [[self alloc] initWithChild:child overlay:overlay];
}
#pragma mark - Lifecycle
- (instancetype)initWithChild:(id<ASLayoutable>)child overlay:(id<ASLayoutable>)overlay
{
if (!(self = [super init])) {
return nil;
}
ASDisplayNodeAssertNotNil(child, @"Child that will be overlayed on shouldn't be nil");
[self setChild:child atIndex:kUnderlayChildIndex];
self.overlay = overlay;
return self;
}
#pragma mark - Setter / Getter
- (void)setOverlay:(id<ASLayoutable>)overlay
{
[super setChild:overlay forIndex:kOverlayChildIndex];
[super setChild:overlay atIndex:kOverlayChildIndex];
}
- (id<ASLayoutable>)overlay
{
return [super childForIndex:kOverlayChildIndex];
return [super childAtIndex:kOverlayChildIndex];
}
#pragma mark - ASLayoutSpec
/**
First layout the contents, then fit the overlay on top of it.
*/
@@ -51,7 +60,7 @@ static NSUInteger const kOverlayChildIndex = 1;
restrictedToSize:(ASLayoutableSize)size
relativeToParentSize:(CGSize)parentSize
{
ASLayout *contentsLayout = [self.child layoutThatFits:constrainedSize parentSize:parentSize];
ASLayout *contentsLayout = [[super childAtIndex:kUnderlayChildIndex] layoutThatFits:constrainedSize parentSize:parentSize];
contentsLayout.position = CGPointZero;
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
if (self.overlay) {