Add a block API to provide an ASLayoutSpec without having to subclass ASDisplayNode

This commit is contained in:
Michael Schneider
2016-04-20 19:16:54 -07:00
parent dd4853bf3a
commit 87a37a283e
4 changed files with 50 additions and 17 deletions

View File

@@ -42,6 +42,11 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode * _Nonnull node);
*/
typedef void (^ASDisplayNodeContextModifier)(_Nonnull CGContextRef context);
/**
* ASDisplayNode layout spec block. This block can be used instead of implementing layoutSpecThatFits: in subclass
*/
typedef ASLayoutSpec * _Nonnull(^ASLayoutSpecBlock)(ASSizeRange constrainedSize);
/**
Interface state is available on ASDisplayNode and ASViewController, and
allows checking whether a node is in an interface situation where it is prudent to trigger certain
@@ -252,6 +257,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize;
/**
* @abstract Provides a way to declare a block to provide an ASLayoutSpec without having to subclass ASDisplayNode and
* implement layoutSpecThatFits:
*
* @return The block used to provide a ASLayoutSpec
*
* @warning Overwriting layoutSpecThatFits: in a subclass and providing a layoutSpecBlock block is currently not supported
*/
@property (nonatomic, readwrite, copy, nullable) ASLayoutSpecBlock layoutSpecBlock;
/**
* @abstract Return the calculated size.
*