mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-05 20:22:15 +00:00
Some commit
This commit is contained in:
parent
5226879291
commit
c61ba65ba3
@ -254,6 +254,8 @@ extern NSInteger const ASDefaultDrawingPriority;
|
||||
|
||||
/** @name Managing dimensions */
|
||||
|
||||
- (CGSize)sizeThatFits:(CGSize)size;
|
||||
|
||||
/**
|
||||
* @abstract Asks the node to return a layout based on given size range.
|
||||
*
|
||||
|
@ -703,6 +703,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
|
||||
#pragma mark - Layout
|
||||
|
||||
- (CGSize)sizeThatFits:(CGSize)size
|
||||
{
|
||||
return [self layoutThatFits:ASSizeRangeMake(CGSizeZero, size)].size;
|
||||
}
|
||||
|
||||
- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
@ -1495,15 +1500,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
|
||||
// If no measure pass happened or the bounds changed between layout passes we manually trigger a measurement pass
|
||||
// for the node using a size range equal to whatever bounds were provided to the node
|
||||
if (hasDirtyLayout) {
|
||||
if (CGRectEqualToRect(bounds, CGRectZero)) {
|
||||
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
|
||||
} else {
|
||||
if (CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO) {
|
||||
[self layoutThatFits:ASSizeRangeMake(bounds.size)];
|
||||
} else {
|
||||
[self layoutThatFits:_calculatedDisplayNodeLayout->constrainedSize];
|
||||
}
|
||||
if (CGRectEqualToRect(bounds, CGRectZero)) {
|
||||
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
|
||||
} else {
|
||||
if (CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO) {
|
||||
[self layoutThatFits:ASSizeRangeMake(bounds.size)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,6 +237,17 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
return [self _rendererWithBounds:self.threadSafeBounds];
|
||||
}
|
||||
|
||||
- (ASTextKitRenderer *)_rendererWithBoundsSlow:(CGRect)bounds
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
CGSize constrainedSize = bounds.size;
|
||||
constrainedSize.width -= (_textContainerInset.left + _textContainerInset.right);
|
||||
constrainedSize.height -= (_textContainerInset.top + _textContainerInset.bottom);
|
||||
return [[ASTextKitRenderer alloc] initWithTextKitAttributes:[self _rendererAttributes]
|
||||
constrainedSize:constrainedSize];
|
||||
}
|
||||
|
||||
- (ASTextKitRenderer *)_rendererWithBounds:(CGRect)bounds
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
@ -404,7 +415,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
|
||||
[self setNeedsDisplay];
|
||||
|
||||
CGSize size = [self _renderer].size;
|
||||
CGSize size = [self _rendererWithBoundsSlow:{.size=constrainedSize}].size;
|
||||
if (_attributedText.length > 0) {
|
||||
self.style.ascender = [[self class] ascenderWithAttributedString:_attributedText];
|
||||
self.style.descender = [[_attributedText attribute:NSFontAttributeName atIndex:_attributedText.length - 1 effectiveRange:NULL] descender];
|
||||
@ -537,7 +548,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
|
||||
CGContextTranslateCTM(context, _textContainerInset.left, _textContainerInset.top);
|
||||
|
||||
ASTextKitRenderer *renderer = [self _rendererWithBounds:drawParameterBounds];
|
||||
ASTextKitRenderer *renderer = [self _rendererWithBoundsSlow:drawParameterBounds];
|
||||
|
||||
// Fill background
|
||||
if (backgroundColor != nil) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
Loading…
x
Reference in New Issue
Block a user