mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Some commit
This commit is contained in:
@@ -28,6 +28,8 @@ static const NSInteger kImageHeight = 200;
|
||||
@property (nonatomic, copy) NSString *imageCategory;
|
||||
@property (nonatomic, strong) ASCollectionNode *collectionNode;
|
||||
|
||||
@property (nonatomic, strong) ASDisplayNode *backgroundNode;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,36 @@
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
#import "DetailRootNode.h"
|
||||
#import "SampleSizingNode.h"
|
||||
|
||||
@interface DetailViewController ()
|
||||
@property (strong, nonatomic) SampleSizingNode *sizingNode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DetailViewController
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (instancetype)initWithNode:(DetailRootNode *)node
|
||||
{
|
||||
self = [super initWithNode:node];
|
||||
|
||||
// Set the sizing delegate of the root node to the container
|
||||
self.sizingNode = [SampleSizingNode new];
|
||||
self.sizingNode.autoresizingMask = UIViewAutoresizingNone;
|
||||
self.sizingNode.delegate = self;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self.view addSubnode:self.sizingNode];
|
||||
}
|
||||
|
||||
#pragma mark - Rotation
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||
@@ -30,4 +57,32 @@
|
||||
[self.node.collectionNode.view.collectionViewLayout invalidateLayout];
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews
|
||||
{
|
||||
[super viewDidLayoutSubviews];
|
||||
|
||||
[self updateNodeLayout];
|
||||
}
|
||||
|
||||
#pragma mark - Update the node based on the new size
|
||||
|
||||
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode
|
||||
{
|
||||
// ASDisplayNodeSizingDelegate / ASDisplayNodeSizingHandlers
|
||||
[self updateNodeLayout];
|
||||
}
|
||||
|
||||
- (void)updateNodeLayout
|
||||
{
|
||||
// Adjust the layout on the new layout
|
||||
|
||||
// Use the bounds of the view and get the fitting size
|
||||
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, 100.0)];
|
||||
size.width -= 10;
|
||||
//[self.sizingNode setNeedsLayout];
|
||||
self.sizingNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
||||
(self.view.bounds.size.height - size.height) / 2.0,
|
||||
size.width, size.height);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
17
examples/ASViewController/Sample/SampleSizingNode.h
Normal file
17
examples/ASViewController/Sample/SampleSizingNode.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SampleSizingNode.h
|
||||
// Sample
|
||||
//
|
||||
// Created by Michael Schneider on 11/10/16.
|
||||
// Copyright © 2016 AsyncDisplayKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
@interface ASDisplayNodeSizingDelegate : NSObject
|
||||
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode;
|
||||
@end
|
||||
|
||||
@interface SampleSizingNode : ASDisplayNode
|
||||
@property (nonatomic, weak) id delegate;
|
||||
@end
|
||||
86
examples/ASViewController/Sample/SampleSizingNode.m
Normal file
86
examples/ASViewController/Sample/SampleSizingNode.m
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// SampleSizingNode.m
|
||||
// Sample
|
||||
//
|
||||
// Created by Michael Schneider on 11/10/16.
|
||||
// Copyright © 2016 AsyncDisplayKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SampleSizingNode.h"
|
||||
|
||||
@interface SampleSizingNode ()
|
||||
@property (nonatomic, strong) ASDisplayNode *subnode;
|
||||
@property (nonatomic, assign) NSInteger state;
|
||||
|
||||
@property (nonatomic, strong) ASTextNode *textNode;
|
||||
@end
|
||||
|
||||
@implementation SampleSizingNode
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
self.automaticallyManagesSubnodes = YES;
|
||||
|
||||
//_subnode = [ASDisplayNode new];
|
||||
//_subnode.backgroundColor = [UIColor redColor];
|
||||
|
||||
_textNode = [ASTextNode new];
|
||||
_textNode.backgroundColor = [UIColor blueColor];
|
||||
_textNode.autoresizingMask = UIViewAutoresizingNone;
|
||||
|
||||
_state = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)didLoad
|
||||
{
|
||||
[super didLoad];
|
||||
|
||||
[self stateChanged];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
self.state = 1;
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - State Management
|
||||
|
||||
- (void)setState:(NSInteger)state
|
||||
{
|
||||
_state = state;
|
||||
[self stateChanged];
|
||||
}
|
||||
|
||||
- (void)stateChanged
|
||||
{
|
||||
NSString *text = self.state == 0 ? @"Bla Bla" : @"Bla Blaa sd fkj as;l dkf";
|
||||
self.textNode.attributedText = [[NSAttributedString alloc] initWithString:text];
|
||||
|
||||
// Invalidate the layout for now and bubble it up until the root node to let the size provider know that
|
||||
// that a size change happened
|
||||
[self setNeedsLayout];
|
||||
|
||||
// If someone calls `setNeedsLayout` we have to inform the sizing delegate of the root node to be able
|
||||
// to let them now that a size change happened
|
||||
if ([self.delegate respondsToSelector:@selector(displayNodeDidInvalidateSize:)]) {
|
||||
[self.delegate performSelector:@selector(displayNodeDidInvalidateSize:) withObject:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - ASDisplayNode
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
// Layout description based on state
|
||||
//self.subnode.style.preferredSize = constrainedSize.max;
|
||||
UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:_textNode];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user