mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Improve ASViewController example
This commit is contained in:
@@ -21,32 +21,33 @@
|
||||
self = [super init];
|
||||
if (self == nil) { return self; }
|
||||
|
||||
_imageNode = [ASNetworkImageNode new];
|
||||
_imageNode = [[ASNetworkImageNode alloc] init];
|
||||
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
|
||||
[self addSubnode:_imageNode];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - ASDisplayNode
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASStaticLayoutSpec *staticSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.imageNode]];
|
||||
self.imageNode.position = CGPointZero;
|
||||
self.imageNode.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(constrainedSize.max);
|
||||
return staticSpec;
|
||||
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.imageNode]];
|
||||
}
|
||||
|
||||
- (void)fetchData
|
||||
- (void)layoutDidFinish
|
||||
{
|
||||
[super fetchData];
|
||||
[super layoutDidFinish];
|
||||
|
||||
[self loadImage];
|
||||
// In general set URL of ASNetworkImageNode as soon as possible. Ideally in init or a
|
||||
// view model setter method.
|
||||
// In this case as we need to know the size of the node the url is set in layoutDidFinish so
|
||||
// we have the calculatedSize available
|
||||
self.imageNode.URL = [self imageURL];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Image
|
||||
|
||||
- (NSURL *)imageURL
|
||||
@@ -56,9 +57,4 @@
|
||||
return [NSURL URLWithString:imageURLString];
|
||||
}
|
||||
|
||||
- (void)loadImage
|
||||
{
|
||||
self.imageNode.URL = self.imageURL;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user