Integrate new layout nodes to the framework.

- Introduce ASLayoutNode and its subclasses.
- ASDisplayNode measures its ASLayoutNode and cache the result (ASLayout). Calculated size and position of each subnode can be retrieved from the calculated layout.
- Custom nodes need to override -layoutNodeThatFits:(CGSize) instead of -calculateSizeThatFits:(CGSize).
- Custom nodes do not need to layout its subnodes (in -layout:) anymore. ASDisplayNode can handle the job most of the time, by walking through its layout tree.
- ASCompositeNode is used to embed (display) subnodes to a node's layout. That way, each subnode will also be measured while the parent node is measuring. And the parent node knows where its subnodes are within its layout.
This commit is contained in:
Huy Nguyen
2015-05-28 20:36:55 +03:00
parent f8531f467d
commit abe98d5b09
13 changed files with 315 additions and 119 deletions

View File

@@ -17,6 +17,9 @@
#import "ASImageNode+CGExtras.h"
#import "ASInternalHelpers.h"
#import "ASLayoutNode.h"
@interface _ASImageNodeDrawParameters : NSObject
@property (nonatomic, assign, readonly) BOOL cropEnabled;
@@ -82,7 +85,7 @@
return nil;
// TODO can this be removed?
self.contentsScale = ASDisplayNodeScreenScale();
self.contentsScale = ASScreenScale();
self.contentMode = UIViewContentModeScaleAspectFill;
self.opaque = NO;
@@ -106,13 +109,13 @@
return nil;
}
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
- (ASLayout *)calculateLayoutThatFits:(CGSize)constrainedSize
{
ASDN::MutexLocker l(_imageLock);
CGSize size = CGSizeZero;
if (_image)
return _image.size;
else
return CGSizeZero;
size = _image.size;
return [ASLayout newWithNode:[ASLayoutNode new] size:size];
}
- (void)setImage:(UIImage *)image
@@ -123,7 +126,7 @@
ASDN::MutexUnlocker u(_imageLock);
ASDisplayNodePerformBlockOnMainThread(^{
[self invalidateCalculatedSize];
[self invalidateCalculatedLayout];
[self setNeedsDisplay];
});
}