Merge pull request #1707 from maicki/FixPlaceholderNotAppearing

[ASDisplayNode] Fix placeholder image is not appearing if size of node changed after initial placement
This commit is contained in:
appleguy
2016-06-04 16:48:24 -07:00
4 changed files with 28 additions and 2 deletions

View File

@@ -1088,7 +1088,13 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
// with negative sizes after applying margins, which will cause
// measureWithSizeRange: on subnodes to assert.
if (!CGRectEqualToRect(bounds, CGRectZero)) {
// Handle placeholder layer creation in case the size of the node changed after the initial placeholder layer
// was created
if ([self _shouldHavePlaceholderLayer]) {
[self _setupPlaceholderLayerIfNeeded];
}
_placeholderLayer.frame = bounds;
[self layout];
[self layoutDidFinish];
}

View File

@@ -60,6 +60,10 @@
- (UIImage *)placeholderImage
{
CGSize size = self.calculatedSize;
if (CGSizeEqualToSize(size, CGSizeZero)) {
return nil;
}
UIGraphicsBeginImageContext(size);
[[UIColor colorWithWhite:0.9 alpha:1] setFill];
UIRectFill((CGRect){CGPointZero, size});
@@ -78,6 +82,8 @@
- (void)layout
{
[super layout];
CGSize textSize = _textNode.calculatedSize;
CGSize needyChildSize = _needyChildNode.calculatedSize;

View File

@@ -15,9 +15,14 @@
static CGFloat const kASDKLogoAspectRatio = 2.79;
@interface ASImageNode (ForwardWorkaround)
// This is a workaround until subclass overriding of custom drawing class methods is fixed
- (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock;
@end
@implementation SlowpokeImageNode
+ (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock
- (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock
{
usleep( (long)(0.5 * USEC_PER_SEC) ); // artificial delay of 0.5s
@@ -46,6 +51,10 @@ static CGFloat const kASDKLogoAspectRatio = 2.79;
- (UIImage *)placeholderImage
{
CGSize size = self.calculatedSize;
if (CGSizeEqualToSize(size, CGSizeZero)) {
return nil;
}
UIGraphicsBeginImageContext(size);
[[UIColor whiteColor] setFill];
[[UIColor colorWithWhite:0.9 alpha:1] setStroke];

View File

@@ -13,9 +13,14 @@
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
@interface ASTextNode (ForwardWorkaround)
// This is a workaround until subclass overriding of custom drawing class methods is fixed
- (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing;
@end
@implementation SlowpokeTextNode
+ (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing
- (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing
{
usleep( (long)(1.0 * USEC_PER_SEC) ); // artificial delay of 1.0