mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Some more stuff in flux
This commit is contained in:
parent
c61ba65ba3
commit
6f40e9a654
@ -716,10 +716,20 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (ASLayout *)cacheLayoutThatFits:(ASSizeRange)constrainedSize
|
||||||
|
{
|
||||||
|
return [self cacheLayoutThatFits:constrainedSize parentSize:constrainedSize.max];
|
||||||
|
}
|
||||||
|
|
||||||
- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)parentSize
|
- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)parentSize
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
|
|
||||||
|
return [self calculateLayoutThatFits:constrainedSize restrictedToSize:self.style.size relativeToParentSize:parentSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASLayout *)cacheLayoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)parentSize
|
||||||
|
{
|
||||||
if ([self shouldCalculateLayoutWithConstrainedSize:constrainedSize parentSize:parentSize] == NO) {
|
if ([self shouldCalculateLayoutWithConstrainedSize:constrainedSize parentSize:parentSize] == NO) {
|
||||||
ASDisplayNodeAssertNotNil(_calculatedDisplayNodeLayout->layout, @"-[ASDisplayNode layoutThatFits:parentSize:] _layout should not be nil! %@", self);
|
ASDisplayNodeAssertNotNil(_calculatedDisplayNodeLayout->layout, @"-[ASDisplayNode layoutThatFits:parentSize:] _layout should not be nil! %@", self);
|
||||||
return _calculatedDisplayNodeLayout->layout ? : [ASLayout layoutWithLayoutElement:self size:{0, 0}];
|
return _calculatedDisplayNodeLayout->layout ? : [ASLayout layoutWithLayoutElement:self size:{0, 0}];
|
||||||
@ -1504,7 +1514,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
|
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
|
||||||
} else {
|
} else {
|
||||||
if (CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO) {
|
if (CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO) {
|
||||||
[self layoutThatFits:ASSizeRangeMake(bounds.size)];
|
[self cacheLayoutThatFits:ASSizeRangeMake(bounds.size)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,12 +49,17 @@
|
|||||||
[self.view addSubnode:self.sizingNode];
|
[self.view addSubnode:self.sizingNode];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Rotation
|
- (void)viewWillAppear:(BOOL)animated
|
||||||
|
|
||||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
|
||||||
{
|
{
|
||||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
[super viewWillAppear:animated];
|
||||||
[self.node.collectionNode.view.collectionViewLayout invalidateLayout];
|
|
||||||
|
// Initial size of sizing node
|
||||||
|
self.sizingNode.frame = CGRectMake(100, 100, 50, 50);
|
||||||
|
|
||||||
|
// Start some timer to chang ethe size randomly
|
||||||
|
[NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
||||||
|
//[self updateNodeLayoutRandom];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidLayoutSubviews
|
- (void)viewDidLayoutSubviews
|
||||||
@ -66,23 +71,61 @@
|
|||||||
|
|
||||||
#pragma mark - Update the node based on the new size
|
#pragma mark - Update the node based on the new size
|
||||||
|
|
||||||
|
// The sizing delegate will get callbacks if the size did invalidate of the display node. It's the job of the delegate
|
||||||
|
// to get the new size from the display node and update the frame based on the returned size
|
||||||
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode
|
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode
|
||||||
{
|
{
|
||||||
// ASDisplayNodeSizingDelegate / ASDisplayNodeSizingHandlers
|
|
||||||
[self updateNodeLayout];
|
[self updateNodeLayout];
|
||||||
|
|
||||||
|
/*dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
|
[self updateNodeLayoutRandom];
|
||||||
|
});*/
|
||||||
|
|
||||||
|
/*[NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
||||||
|
[self updateNodeLayoutRandom];
|
||||||
|
}];*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateNodeLayout
|
- (void)updateNodeLayout
|
||||||
{
|
{
|
||||||
// Adjust the layout on the new layout
|
// Adjust the layout on the new layout
|
||||||
|
//return;
|
||||||
// Use the bounds of the view and get the fitting size
|
// Use the bounds of the view and get the fitting size
|
||||||
|
// This does not have any side effects, but can be called on the main thread without any problems
|
||||||
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, 100.0)];
|
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, 100.0)];
|
||||||
size.width -= 10;
|
//size.width -= 10;
|
||||||
//[self.sizingNode setNeedsLayout];
|
//[self.sizingNode setNeedsLayout];
|
||||||
self.sizingNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
self.sizingNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
||||||
(self.view.bounds.size.height - size.height) / 2.0,
|
(self.view.bounds.size.height - size.height) / 2.0,
|
||||||
size.width, size.height);
|
size.width, size.height);
|
||||||
|
|
||||||
|
//dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
|
self.sizingNode.frame = CGRectInset(self.sizingNode.frame, 10, 10);
|
||||||
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateNodeLayoutRandom
|
||||||
|
{
|
||||||
|
// Pick a randome width and height and set the frame of the node
|
||||||
|
CGSize size = CGSizeZero;
|
||||||
|
size.width = arc4random_uniform(self.view.bounds.size.width);
|
||||||
|
size.height = arc4random_uniform(self.view.bounds.size.height);
|
||||||
|
|
||||||
|
//[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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark - Rotation
|
||||||
|
|
||||||
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||||
|
{
|
||||||
|
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||||
|
[self.node.collectionNode.view.collectionViewLayout invalidateLayout];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||||
|
|
||||||
|
// ASDisplayNodeSizingDelegate / ASDisplayNodeSizingHandlers
|
||||||
@interface ASDisplayNodeSizingDelegate : NSObject
|
@interface ASDisplayNodeSizingDelegate : NSObject
|
||||||
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode;
|
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -24,12 +24,19 @@
|
|||||||
|
|
||||||
self.automaticallyManagesSubnodes = YES;
|
self.automaticallyManagesSubnodes = YES;
|
||||||
|
|
||||||
//_subnode = [ASDisplayNode new];
|
self.backgroundColor = [UIColor greenColor];
|
||||||
//_subnode.backgroundColor = [UIColor redColor];
|
|
||||||
|
|
||||||
_textNode = [ASTextNode new];
|
_textNode = [ASTextNode new];
|
||||||
_textNode.backgroundColor = [UIColor blueColor];
|
_textNode.backgroundColor = [UIColor blueColor];
|
||||||
_textNode.autoresizingMask = UIViewAutoresizingNone;
|
//_textNode.autoresizingMask = UIViewAutoresizingNone;
|
||||||
|
|
||||||
|
_subnode = [ASDisplayNode new];
|
||||||
|
_subnode.backgroundColor = [UIColor redColor];
|
||||||
|
_subnode.automaticallyManagesSubnodes = YES;
|
||||||
|
_subnode.layoutSpecBlock = ^ASLayoutSpec *(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
|
||||||
|
UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||||
|
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:_textNode];
|
||||||
|
};
|
||||||
|
|
||||||
_state = 0;
|
_state = 0;
|
||||||
}
|
}
|
||||||
@ -61,7 +68,8 @@
|
|||||||
self.textNode.attributedText = [[NSAttributedString alloc] initWithString:text];
|
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
|
// 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
|
// that a size change could have happened
|
||||||
|
// --> Do we even need to invalidate the layout?
|
||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
|
|
||||||
// If someone calls `setNeedsLayout` we have to inform the sizing delegate of the root node to be able
|
// If someone calls `setNeedsLayout` we have to inform the sizing delegate of the root node to be able
|
||||||
@ -77,9 +85,14 @@
|
|||||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||||
{
|
{
|
||||||
// Layout description based on state
|
// Layout description based on state
|
||||||
//self.subnode.style.preferredSize = constrainedSize.max;
|
// UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||||
UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
|
// return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:_textNode];
|
||||||
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:_textNode];
|
|
||||||
|
//return [ASWrapperLayoutSpec wrapperWithLayoutElement:self.subnode];
|
||||||
|
return [ASCenterLayoutSpec
|
||||||
|
centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY
|
||||||
|
sizingOptions:ASCenterLayoutSpecSizingOptionDefault
|
||||||
|
child:self.subnode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user