This repository was archived by the owner on Feb 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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];
You can’t perform that action at this time.
0 commit comments