From 20523821f9a1c4bd9bfea5b8342b9e3337f382c5 Mon Sep 17 00:00:00 2001 From: Levi McCallum Date: Mon, 6 Jun 2016 13:12:10 -0700 Subject: [PATCH] Revert "Merge pull request #1673 from maicki/AddAutomaticMeasureBeforeLayout" This reverts commit 2e384a32e15d34ea8f963dbc4e44aaa297ca019b, reversing changes made to b8618d3151d9714d24ccfd935b92a99b774442f1. --- AsyncDisplayKit/ASDisplayNode.h | 2 - AsyncDisplayKit/ASDisplayNode.mm | 80 +++++++++---------------- examples/Videos/Sample/ViewController.h | 4 +- examples/Videos/Sample/ViewController.m | 28 ++++----- 4 files changed, 43 insertions(+), 71 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.h b/AsyncDisplayKit/ASDisplayNode.h index ff63eeee2d..7c53e93a05 100644 --- a/AsyncDisplayKit/ASDisplayNode.h +++ b/AsyncDisplayKit/ASDisplayNode.h @@ -15,8 +15,6 @@ #import #import -#define ASDisplayNodeLoggingEnabled 0 - @class ASDisplayNode; /** diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 04860b4f11..ed9c3a9d55 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -48,11 +48,8 @@ NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp = @"AS @end -#if ASDisplayNodeLoggingEnabled - #define LOG(...) NSLog(__VA_ARGS__) -#else - #define LOG(...) -#endif +//#define LOG(...) NSLog(__VA_ARGS__) +#define LOG(...) // Conditionally time these scopes to our debug ivars (only exist in debug/profile builds) #if TIME_DISPLAYNODE_OPS @@ -1076,60 +1073,19 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c) ASDisplayNodeAssertMainThread(); ASDN::MutexLocker l(_propertyLock); CGRect bounds = self.bounds; - - [self measureNodeWithBoundsIfNecessary:bounds]; - - // Performing layout on a zero-bounds view often results in frame calculations - // with negative sizes after applying margins, which will cause - // measureWithSizeRange: on subnodes to assert. - if (!CGRectEqualToRect(bounds, CGRectZero)) { - // Handle placeholder layer creation in case the size of the node changed after the initial placeholder layer - // was created - if ([self _shouldHavePlaceholderLayer]) { - [self _setupPlaceholderLayerIfNeeded]; - } - _placeholderLayer.frame = bounds; - - [self layout]; - [self layoutDidFinish]; - } -} - -- (void)measureNodeWithBoundsIfNecessary:(CGRect)bounds -{ - // Normally measure will be called before layout occurs. If this doesn't happen, nothing is going to call it at all. - // We simply call measureWithSizeRange: using a size range equal to whatever bounds were provided to that element or - // try to measure the node with the largest size as possible - if (self.supernode == nil && !self.supportsRangeManagedInterfaceState && [self _hasDirtyLayout] == NO) { - 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 { - [self measureWithSizeRange:ASSizeRangeMake(CGSizeZero, bounds.size)]; - } - } -} - -- (void)layout -{ - ASDisplayNodeAssertMainThread(); - - if ([self _hasDirtyLayout]) { + if (CGRectEqualToRect(bounds, CGRectZero)) { + // Performing layout on a zero-bounds view often results in frame calculations + // with negative sizes after applying margins, which will cause + // measureWithSizeRange: on subnodes to assert. return; } - - [self __layoutSublayouts]; -} - -- (void)__layoutSublayouts -{ - for (ASLayout *subnodeLayout in _layout.immediateSublayouts) { - ((ASDisplayNode *)subnodeLayout.layoutableObject).frame = [subnodeLayout frame]; - } + _placeholderLayer.frame = bounds; + [self layout]; + [self layoutDidFinish]; } - (void)layoutDidFinish { - // Hook for subclasses } - (CATransform3D)_transformToAncestor:(ASDisplayNode *)ancestor @@ -2417,6 +2373,24 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock) } } +- (void)layout +{ + ASDisplayNodeAssertMainThread(); + + if (![self _hasDirtyLayout]) { + return; + } + + [self __layoutSublayouts]; +} + +- (void)__layoutSublayouts +{ + for (ASLayout *subnodeLayout in _layout.immediateSublayouts) { + ((ASDisplayNode *)subnodeLayout.layoutableObject).frame = [subnodeLayout frame]; + } +} + - (void)displayWillStart { ASDisplayNodeAssertMainThread(); diff --git a/examples/Videos/Sample/ViewController.h b/examples/Videos/Sample/ViewController.h index 7549a97db6..1664a00082 100644 --- a/examples/Videos/Sample/ViewController.h +++ b/examples/Videos/Sample/ViewController.h @@ -8,8 +8,8 @@ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#include +#import +#import @interface ViewController : UIViewController diff --git a/examples/Videos/Sample/ViewController.m b/examples/Videos/Sample/ViewController.m index 289d5443d4..db1f18659d 100644 --- a/examples/Videos/Sample/ViewController.m +++ b/examples/Videos/Sample/ViewController.m @@ -10,7 +10,8 @@ */ #import "ViewController.h" -#import +#import "ASLayoutSpec.h" +#import "ASStaticLayoutSpec.h" @interface ViewController() @property (nonatomic, strong) ASDisplayNode *rootNode; @@ -21,23 +22,12 @@ #pragma mark - UIViewController -- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +- (void)viewWillAppear:(BOOL)animated { - self = [super initWithNibName:nil bundle:nil]; - if (self) { + [super viewWillAppear:animated]; - - } - return self; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - // Root node for the view controller _rootNode = [ASDisplayNode new]; - _rootNode.frame = self.view.bounds; _rootNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; ASVideoNode *guitarVideoNode = self.guitarVideoNode; @@ -64,6 +54,16 @@ [self.view addSubnode:_rootNode]; } +- (void)viewDidLayoutSubviews +{ + [super viewDidLayoutSubviews]; + + // After all subviews are layed out we have to measure it and move the root node to the right place + CGSize viewSize = self.view.bounds.size; + [self.rootNode measureWithSizeRange:ASSizeRangeMake(viewSize, viewSize)]; + [self.rootNode setNeedsLayout]; +} + #pragma mark - Getter / Setter - (ASVideoNode *)guitarVideoNode;