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

Commit 2bc701d

Browse files
master-neviAdlai Holler
authored andcommitted
Copy ASTextNode’s implementation of placeholderImage into ASImageNode in order to fix the usage of placeholderColor. (#2866)
1 parent be6faa1 commit 2bc701d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

AsyncDisplayKit/ASImageNode.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "ASEqualityHelpers.h"
2828
#import "ASEqualityHashHelpers.h"
2929
#import "ASWeakMap.h"
30+
#import "CoreGraphics+ASConvenience.h"
3031

3132
// TODO: It would be nice to remove this dependency; it's the only subclass using more than +FrameworkSubclasses.h
3233
#import "ASDisplayNodeInternal.h"
@@ -183,6 +184,26 @@ - (void)dealloc
183184
[self invalidateAnimatedImage];
184185
}
185186

187+
- (UIImage *)placeholderImage
188+
{
189+
// FIXME: Replace this implementation with reusable CALayers that have .backgroundColor set.
190+
// This would completely eliminate the memory and performance cost of the backing store.
191+
CGSize size = self.calculatedSize;
192+
if ((size.width * size.height) < CGFLOAT_EPSILON) {
193+
return nil;
194+
}
195+
196+
ASDN::MutexLocker l(__instanceLock__);
197+
198+
UIGraphicsBeginImageContext(size);
199+
[self.placeholderColor setFill];
200+
UIRectFill(CGRectMake(0, 0, size.width, size.height));
201+
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
202+
UIGraphicsEndImageContext();
203+
204+
return image;
205+
}
206+
186207
#pragma mark - Layout and Sizing
187208

188209
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize

examples/Kittens/Sample/KittenNode.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ - (instancetype)initWithKittenOfSize:(CGSize)size
8888

8989
// kitten image, with a solid background colour serving as placeholder
9090
_imageNode = [[ASNetworkImageNode alloc] init];
91-
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
9291
_imageNode.URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://placekitten.com/%zd/%zd",
9392
(NSInteger)roundl(_kittenSize.width),
9493
(NSInteger)roundl(_kittenSize.height)]];
94+
_imageNode.placeholderFadeDuration = .5;
95+
_imageNode.placeholderColor = ASDisplayNodeDefaultPlaceholderColor();
9596
// _imageNode.contentMode = UIViewContentModeCenter;
9697
[_imageNode addTarget:self action:@selector(toggleNodesSwap) forControlEvents:ASControlNodeEventTouchUpInside];
9798
[self addSubnode:_imageNode];

0 commit comments

Comments
 (0)