From cb37f10ed186f4b95eda578b3e3a91be6300440c Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Thu, 17 Nov 2016 18:36:34 -0800 Subject: [PATCH] Revert sample code --- AsyncDisplayKit/Private/_ASPendingState.mm | 2 +- .../Sample/DetailViewController.m | 158 ----------------- .../Sample/SampleSizingNode.h | 14 -- .../Sample/SampleSizingNode.m | 159 ------------------ examples/Kittens/Sample/KittenNode.mm | 4 +- examples/SocialAppLayout/Sample/PostNode.m | 2 +- 6 files changed, 4 insertions(+), 335 deletions(-) diff --git a/AsyncDisplayKit/Private/_ASPendingState.mm b/AsyncDisplayKit/Private/_ASPendingState.mm index f6c6685a19..c01470e258 100644 --- a/AsyncDisplayKit/Private/_ASPendingState.mm +++ b/AsyncDisplayKit/Private/_ASPendingState.mm @@ -763,7 +763,7 @@ static BOOL defaultAllowsEdgeAntialiasing = NO; if (flags.needsLayout) [layer setNeedsLayout]; - + if (flags.setAsyncTransactionContainer) layer.asyncdisplaykit_asyncTransactionContainer = asyncTransactionContainer; diff --git a/examples/ASViewController/Sample/DetailViewController.m b/examples/ASViewController/Sample/DetailViewController.m index c22357036e..494efd4ffd 100644 --- a/examples/ASViewController/Sample/DetailViewController.m +++ b/examples/ASViewController/Sample/DetailViewController.m @@ -19,167 +19,9 @@ #import #import "DetailRootNode.h" -#import "SampleSizingNode.h" - -@interface DetailViewController ()// -@property (strong, nonatomic) SampleSizingNode *sizingNode; - -@property (strong, nonatomic) ASNetworkImageNode *imageNode; -@property (strong, nonatomic) ASButtonNode *buttonNode; - -@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 - _sizingNode = [SampleSizingNode new]; - _sizingNode.autoresizingMask = UIViewAutoresizingNone; - //_sizingNode.sizingDelegate = self; - - _imageNode = [ASNetworkImageNode new]; - _imageNode.needsDisplayOnBoundsChange = YES; - _imageNode.backgroundColor = [UIColor brownColor]; - _imageNode.style.preferredSize = CGSizeMake(100, 100); - _imageNode.URL = [NSURL URLWithString:@"http://www.classicwings-bavaria.com/bavarian-pictures/chitty-chitty-bang-bang-castle.jpg"]; - - _buttonNode = [ASButtonNode new]; - _buttonNode.backgroundColor = [UIColor yellowColor]; - [_buttonNode setTitle:@"Some Title" withFont:nil withColor:nil forState:ASControlStateNormal]; - [_buttonNode setTitle:@"Some Bla" withFont:nil withColor:[UIColor orangeColor] forState:ASControlStateHighlighted]; - [_buttonNode addTarget:self action:@selector(buttonAction:) forControlEvents:ASControlNodeEventTouchUpInside]; - //_buttonNode.sizingDelegate = self; - - return self; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - [self.view addSubnode:self.sizingNode]; - [self.view addSubnode:self.imageNode]; - [self.view addSubnode:self.buttonNode]; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; - - // Initial size of sizing node - //self.sizingNode.frame = CGRectMake(100, 100, 50, 50); - - //[self displayNodeDidInvalidateSize:self.buttonNode]; - - // Initial size for image node -// self.imageNode.frame = CGRectMake(50, 70, 100, 100); -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// self.imageNode.frame = CGRectMake(50, 70, 70, 50); -// //[self.imageNode setNeedsLayout]; -// //[self.imageNode setNeedsDisplay]; -// }); - - // Start some timer to chang ethe size randomly - [NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) { - //[self updateNodeLayoutRandom]; - }]; -} - -- (void)viewDidLayoutSubviews -{ - [super viewDidLayoutSubviews]; - - // Updat the sizing for the button node - [self updateButtonNodeLayout]; - - // Update the sizing node layout - [self updateNodeLayout]; -} - -#pragma mark - Update the node based on the new size - -- (void)updateButtonNodeLayout -{ - //[self.buttonNode sizeToFit]; - CGSize size = [self.buttonNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))].size; - self.buttonNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0, - 100, - size.width, - size.height); - - //CGSize s = [self.buttonNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - //self.buttonNode.frame = CGRectMake(100, 100, s.width, s.height); -} - -// 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 -//{ -// if (displayNode == self.buttonNode) { -// [self updateButtonNodeLayout]; -// return; -// } -// -// [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 -{ - // Adjust the layout on the new layout - //return; - // 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 layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, 100.0))].size; - //size.width -= 10; - //[self.sizingNode setNeedsLayout]; - self.sizingNode.frame = CGRectMake((CGRectGetWidth(self.view.bounds) - size.width) / 2.0, - (CGRectGetHeight(self.view.bounds) - size.height) / 2.0, - size.width, - size.height); - - //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - // Decrease the frame a bit - self.sizingNode.frame = CGRectInset(self.sizingNode.frame, 10, 10); - //}); -} - -- (void)updateNodeLayoutRandom -{ - CGRect bounds = self.view.bounds; - - // Pick a randome width and height and set the frame of the node - CGSize size = CGSizeZero; - size.width = arc4random_uniform(CGRectGetWidth(bounds)); - size.height = arc4random_uniform(CGRectGetHeight(bounds)); - - //[self.sizingNode setNeedsLayout]; - self.sizingNode.frame = CGRectMake((CGRectGetWidth(bounds) - size.width) / 2.0, - (CGRectGetHeight(bounds) - size.height) / 2.0, - size.width, - size.height); - -} - -#pragma mark - - -- (void)buttonAction:(id)sender -{ - NSLog(@"Button Sender"); -} - #pragma mark - Rotation - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator diff --git a/examples/ASViewController/Sample/SampleSizingNode.h b/examples/ASViewController/Sample/SampleSizingNode.h index 57ecdb7df0..e69de29bb2 100644 --- a/examples/ASViewController/Sample/SampleSizingNode.h +++ b/examples/ASViewController/Sample/SampleSizingNode.h @@ -1,14 +0,0 @@ -// -// SampleSizingNode.h -// Sample -// -// Created by Michael Schneider on 11/10/16. -// Copyright © 2016 AsyncDisplayKit. All rights reserved. -// - -#import - - -@interface SampleSizingNode : ASDisplayNode - -@end diff --git a/examples/ASViewController/Sample/SampleSizingNode.m b/examples/ASViewController/Sample/SampleSizingNode.m index d7ff1c4e86..e69de29bb2 100644 --- a/examples/ASViewController/Sample/SampleSizingNode.m +++ b/examples/ASViewController/Sample/SampleSizingNode.m @@ -1,159 +0,0 @@ -// -// SampleSizingNode.m -// Sample -// -// Created by Michael Schneider on 11/10/16. -// Copyright © 2016 AsyncDisplayKit. All rights reserved. -// - -#import "SampleSizingNode.h" - -@interface SampleSizingNodeSubnode : ASDisplayNode -@property (strong, nonatomic) ASTextNode *textNode; -@end - -@implementation SampleSizingNodeSubnode - -- (void)layout -{ - [super layout]; - - // Manual layout after the normal layout engine did it's job - // Calculated size can be used after the layout spec pass happened - //self.textNode.frame = CGRectMake(self.textNode.frame.origin.x, self.textNode.frame.origin.y, self.textNode.calculatedSize.width, 20); -} - -@end - -@interface SampleSizingNode () -@property (nonatomic, assign) NSInteger state; - -@property (nonatomic, strong) SampleSizingNodeSubnode *subnode; -@property (nonatomic, strong) ASTextNode *textNode; -@property (nonatomic, strong) ASNetworkImageNode *imageNode; -@end - -@implementation SampleSizingNode - -- (instancetype)init -{ - self = [super init]; - if (self) { - - self.automaticallyManagesSubnodes = YES; - - self.backgroundColor = [UIColor greenColor]; - - _textNode = [ASTextNode new]; - _textNode.backgroundColor = [UIColor blueColor]; - - _imageNode = [ASNetworkImageNode new]; - _imageNode.URL = [NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Mont_Blanc_oct_2004.JPG/280px-Mont_Blanc_oct_2004.JPG"]; - _imageNode.backgroundColor = [UIColor brownColor]; - _imageNode.needsDisplayOnBoundsChange = YES; - _imageNode.style.height = ASDimensionMakeWithFraction(1.0); - _imageNode.style.width = ASDimensionMake(50.0); - - - _subnode = [SampleSizingNodeSubnode new]; - _subnode.textNode = _textNode; - _subnode.backgroundColor = [UIColor redColor]; - _subnode.automaticallyManagesSubnodes = YES; - - // Layout description via layoutSpecBlock - __weak __typeof(self) weakSelf = self; - _subnode.layoutSpecBlock = ^ASLayoutSpec *(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) { - - UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10); - ASInsetLayoutSpec *textInsetSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:weakSelf.textNode]; - textInsetSpec.style.flexShrink = 1.0; - - return [ASStackLayoutSpec - stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal - spacing:0.0 - justifyContent:ASStackLayoutJustifyContentStart - alignItems:ASStackLayoutAlignItemsStart - children:@[weakSelf.imageNode, textInsetSpec]]; - //return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithSizing:ASAbsoluteLayoutSpecSizingSizeToFit children:@[_imageNode, insetSpec]]; - }; - - _state = 0; - } - return self; -} - -- (void)didLoad -{ - [super didLoad]; - - - // Initial state - self.state = 0; - - // Simulate a state change of the node - 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; - - // Set text based on state - NSString *text = state == 0 ? @"Bla Bla" : @"Bla Blaa sd fkj as;l dkf"; - self.textNode.attributedText = [[NSAttributedString alloc] initWithString:text]; - - //self.imageNode.style.width = state == 0 ? ASDimensionMake(30.0) : ASDimensionMake(50.0); - - // Let the root node know there can be a size change happened. If we will not call this the text node will just - // use it's own bounds and layout again in the next layout pass what can result in truncation - [self invalidateCalculatedLayoutSizingBlaBla]; -} - -// Invalidates the current layout and bubbles up the setNeedsLayout call to the root node. The root node will inform -// the sizing delegate that a size change did happen and it's up to it to decide if the bounds of the root node should -// change based on this request or not. If no change happened the layout will happen in all subnodes based on the current -// set bounds -- (void)invalidateCalculatedLayoutSizingBlaBla -{ - // Invalidate the layout for now and bubble it up until the root node to let the size provider know that - // that a size change could have happened - // --> Do we even need to invalidate the layout? - [self setNeedsLayout]; - - // If someone calls `invalidateBlaBla TBD` we have to inform the sizing delegate of the root node to be able - // to let them now that a size change happened and it needs to calculate a new layout / size for this node hierarchy - /*if ([self.sizingDelegate respondsToSelector:@selector(displayNodeDidInvalidateSize:)]) { - [self.sizingDelegate performSelector:@selector(displayNodeDidInvalidateSize:) withObject:self]; - }*/ - //[self invalidateSize]; -} - -#pragma mark - ASDisplayNode - -- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize -{ - // Layout description based on state - // UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10); - // return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:_textNode]; - - //return [ASWrapperLayoutSpec wrapperWithLayoutElement:self.subnode]; - return [ASCenterLayoutSpec - centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY - sizingOptions:ASCenterLayoutSpecSizingOptionDefault - child:self.subnode]; -} - -- (void)layout -{ - [super layout]; - - // Layout after the official layout pass happened - //self.subnode.frame = CGRectMake(self.subnode.frame.origin.x, self.subnode.frame.origin.y, 100, self.calculatedSize.height); -} - - -@end diff --git a/examples/Kittens/Sample/KittenNode.mm b/examples/Kittens/Sample/KittenNode.mm index 42a94a055a..67e586b4a7 100644 --- a/examples/Kittens/Sample/KittenNode.mm +++ b/examples/Kittens/Sample/KittenNode.mm @@ -201,7 +201,7 @@ static const CGFloat kInnerPadding = 10.0f; - (void)toggleImageEnlargement { _isImageEnlarged = !_isImageEnlarged; - [self invalidateSize]; + [self setNeedsLayout]; } - (void)toggleNodesSwap @@ -211,7 +211,7 @@ static const CGFloat kInnerPadding = 10.0f; [UIView animateWithDuration:0.15 animations:^{ self.alpha = 0; } completion:^(BOOL finished) { - [self invalidateSize]; + [self setNeedsLayout]; [self.view layoutIfNeeded]; [UIView animateWithDuration:0.15 animations:^{ diff --git a/examples/SocialAppLayout/Sample/PostNode.m b/examples/SocialAppLayout/Sample/PostNode.m index b4abad7a64..3206b00d99 100644 --- a/examples/SocialAppLayout/Sample/PostNode.m +++ b/examples/SocialAppLayout/Sample/PostNode.m @@ -339,7 +339,7 @@ - (void)imageNode:(ASNetworkImageNode *)imageNode didLoadImage:(UIImage *)image { - [self invalidateSize]; + [self setNeedsLayout]; } @end