Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 4f493c4

Browse files
committed
Fix placeholder image is not appearing if size of node changed after initial placement
1 parent 50ca58f commit 4f493c4

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,13 @@ - (void)__layout
10881088
// with negative sizes after applying margins, which will cause
10891089
// measureWithSizeRange: on subnodes to assert.
10901090
if (!CGRectEqualToRect(bounds, CGRectZero)) {
1091+
// Handle placeholder layer creation in case the size of the node changed after the initial placeholder layer
1092+
// was created
1093+
if ([self _shouldHavePlaceholderLayer]) {
1094+
[self _setupPlaceholderLayerIfNeeded];
1095+
}
10911096
_placeholderLayer.frame = bounds;
1097+
10921098
[self layout];
10931099
[self layoutDidFinish];
10941100
}

examples_extra/Placeholders/Sample/PostNode.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ - (instancetype)init
6060
- (UIImage *)placeholderImage
6161
{
6262
CGSize size = self.calculatedSize;
63+
if (CGSizeEqualToSize(size, CGSizeZero)) {
64+
return nil;
65+
}
66+
6367
UIGraphicsBeginImageContext(size);
6468
[[UIColor colorWithWhite:0.9 alpha:1] setFill];
6569
UIRectFill((CGRect){CGPointZero, size});
@@ -78,6 +82,8 @@ - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
7882

7983
- (void)layout
8084
{
85+
[super layout];
86+
8187
CGSize textSize = _textNode.calculatedSize;
8288
CGSize needyChildSize = _needyChildNode.calculatedSize;
8389

examples_extra/Placeholders/Sample/SlowpokeImageNode.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515

1616
static CGFloat const kASDKLogoAspectRatio = 2.79;
1717

18+
@interface ASImageNode (ForwardWorkaround)
19+
// This is a workaround until subclass overwritting of custom drawing class methods is fixed
20+
- (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock;
21+
@end
22+
1823
@implementation SlowpokeImageNode
1924

20-
+ (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock
25+
- (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock
2126
{
2227
usleep( (long)(0.5 * USEC_PER_SEC) ); // artificial delay of 0.5s
2328

@@ -46,6 +51,10 @@ - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
4651
- (UIImage *)placeholderImage
4752
{
4853
CGSize size = self.calculatedSize;
54+
if (CGSizeEqualToSize(size, CGSizeZero)) {
55+
return nil;
56+
}
57+
4958
UIGraphicsBeginImageContext(size);
5059
[[UIColor whiteColor] setFill];
5160
[[UIColor colorWithWhite:0.9 alpha:1] setStroke];

examples_extra/Placeholders/Sample/SlowpokeTextNode.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313

1414
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
1515

16+
@interface ASTextNode (ForwardWorkaround)
17+
// This is a workaround until subclass overwritting of custom drawing class methods is fixed
18+
- (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing;
19+
@end
20+
1621
@implementation SlowpokeTextNode
1722

18-
+ (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing
23+
- (void)drawRect:(CGRect)bounds withParameters:(id<NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing
1924
{
2025
usleep( (long)(1.0 * USEC_PER_SEC) ); // artificial delay of 1.0
2126

0 commit comments

Comments
 (0)