mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
ASViewController example improvements (#2592)
This commit is contained in:
committed by
appleguy
parent
171cc2f527
commit
2ba8239ff5
@@ -221,7 +221,7 @@ ASVisibilityDepthImplementation;
|
||||
{
|
||||
if (AS_AT_LEAST_IOS9) {
|
||||
CGSize viewSize = self.view.bounds.size;
|
||||
return ASSizeRangeMake(viewSize, viewSize);
|
||||
return ASSizeRangeMake(viewSize);
|
||||
} else {
|
||||
return [self _legacyConstrainedSize];
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
self = [super init];
|
||||
if (self == nil) { return self; }
|
||||
|
||||
self.automaticallyManagesSubnodes = YES;
|
||||
|
||||
_imageNode = [[ASNetworkImageNode alloc] init];
|
||||
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
|
||||
[self addSubnode:_imageNode];
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -38,7 +39,7 @@
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
return [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:_imageNode];
|
||||
return [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.0 child:self.imageNode];
|
||||
}
|
||||
|
||||
- (void)layoutDidFinish
|
||||
|
||||
@@ -38,7 +38,10 @@ static const NSInteger kImageHeight = 200;
|
||||
- (instancetype)initWithImageCategory:(NSString *)imageCategory
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil) { return self; }
|
||||
if (self) {
|
||||
// Enable automaticallyManagesSubnodes so the first time the layout pass of the node is happening all nodes that are referenced
|
||||
// in the laaout specification within layoutSpecThatFits: will be added automatically
|
||||
self.automaticallyManagesSubnodes = YES;
|
||||
|
||||
_imageCategory = imageCategory;
|
||||
|
||||
@@ -48,10 +51,7 @@ static const NSInteger kImageHeight = 200;
|
||||
_collectionNode.delegate = self;
|
||||
_collectionNode.dataSource = self;
|
||||
_collectionNode.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
// Enable usesImplicitHierarchyManagement so the first time the layout pass of the node is happening all nodes that are referenced
|
||||
// in layouts within layoutSpecThatFits: will be added automatically
|
||||
self.automaticallyManagesSubnodes = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -66,9 +66,7 @@ static const NSInteger kImageHeight = 200;
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
self.collectionNode.position = CGPointZero;
|
||||
self.collectionNode.style.preferredSize = constrainedSize.max;
|
||||
return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.collectionNode]];
|
||||
return [ASWrapperLayoutSpec wrapperWithLayoutElement:self.collectionNode];
|
||||
}
|
||||
|
||||
#pragma mark - ASCollectionDataSource
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.tableNode.delegate = nil;
|
||||
self.tableNode.dataSource = nil;
|
||||
self.node.delegate = nil;
|
||||
self.node.dataSource = nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,23 +58,15 @@
|
||||
|
||||
self.title = @"Image Categories";
|
||||
|
||||
self.tableNode.delegate = self;
|
||||
self.tableNode.dataSource = self;
|
||||
self.node.delegate = self;
|
||||
self.node.dataSource = self;
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self.tableNode deselectRowAtIndexPath:self.tableNode.indexPathForSelectedRow animated:YES];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Setter / Getter
|
||||
|
||||
- (ASTableNode *)tableNode
|
||||
{
|
||||
return (ASTableNode *)self.node;
|
||||
[self.node deselectRowAtIndexPath:self.node.indexPathForSelectedRow animated:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +79,7 @@
|
||||
|
||||
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// As the block is executed on a background thread we need to cache the image category string outside
|
||||
NSString *imageCategory = self.imageCategories[indexPath.row];
|
||||
return ^{
|
||||
ASTextCellNode *textCellNode = [ASTextCellNode new];
|
||||
|
||||
Reference in New Issue
Block a user