mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-12 17:30:34 +00:00
Copy ASTextNode’s implementation of placeholderImage into ASImageNode in order to fix the usage of placeholderColor. (#2866)
This commit is contained in:
parent
be6faa107a
commit
2bc701d23f
@ -27,6 +27,7 @@
|
||||
#import "ASEqualityHelpers.h"
|
||||
#import "ASEqualityHashHelpers.h"
|
||||
#import "ASWeakMap.h"
|
||||
#import "CoreGraphics+ASConvenience.h"
|
||||
|
||||
// TODO: It would be nice to remove this dependency; it's the only subclass using more than +FrameworkSubclasses.h
|
||||
#import "ASDisplayNodeInternal.h"
|
||||
@ -183,6 +184,26 @@ struct ASImageNodeDrawParameters {
|
||||
[self invalidateAnimatedImage];
|
||||
}
|
||||
|
||||
- (UIImage *)placeholderImage
|
||||
{
|
||||
// FIXME: Replace this implementation with reusable CALayers that have .backgroundColor set.
|
||||
// This would completely eliminate the memory and performance cost of the backing store.
|
||||
CGSize size = self.calculatedSize;
|
||||
if ((size.width * size.height) < CGFLOAT_EPSILON) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
UIGraphicsBeginImageContext(size);
|
||||
[self.placeholderColor setFill];
|
||||
UIRectFill(CGRectMake(0, 0, size.width, size.height));
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
#pragma mark - Layout and Sizing
|
||||
|
||||
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
|
||||
|
||||
@ -88,10 +88,11 @@ static const CGFloat kInnerPadding = 10.0f;
|
||||
|
||||
// kitten image, with a solid background colour serving as placeholder
|
||||
_imageNode = [[ASNetworkImageNode alloc] init];
|
||||
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
|
||||
_imageNode.URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://placekitten.com/%zd/%zd",
|
||||
(NSInteger)roundl(_kittenSize.width),
|
||||
(NSInteger)roundl(_kittenSize.height)]];
|
||||
_imageNode.placeholderFadeDuration = .5;
|
||||
_imageNode.placeholderColor = ASDisplayNodeDefaultPlaceholderColor();
|
||||
// _imageNode.contentMode = UIViewContentModeCenter;
|
||||
[_imageNode addTarget:self action:@selector(toggleNodesSwap) forControlEvents:ASControlNodeEventTouchUpInside];
|
||||
[self addSubnode:_imageNode];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user