Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions AsyncDisplayKit/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#import <AsyncDisplayKit/ASAsciiArtBoxCreator.h>
#import <AsyncDisplayKit/ASLayoutable.h>

#define ASDisplayNodeLoggingEnabled 0

@class ASDisplayNode;

/**
Expand Down
80 changes: 27 additions & 53 deletions AsyncDisplayKit/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ - (void)_staticInitialize;

@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
Expand Down Expand Up @@ -1076,60 +1073,19 @@ - (void)__layout
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
Expand Down Expand Up @@ -2417,6 +2373,24 @@ - (void)applyLayout:(ASLayout *)layout layoutContext:(ASLayoutTransition *)layou
}
}

- (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();
Expand Down
4 changes: 2 additions & 2 deletions examples/Videos/Sample/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <AsyncDisplayKit/ASVideoNode.h>

@interface ViewController : UIViewController

Expand Down
28 changes: 14 additions & 14 deletions examples/Videos/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*/

#import "ViewController.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "ASLayoutSpec.h"
#import "ASStaticLayoutSpec.h"

@interface ViewController()<ASVideoNodeDelegate>
@property (nonatomic, strong) ASDisplayNode *rootNode;
Expand All @@ -21,23 +22,12 @@ @implementation ViewController

#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;
Expand All @@ -64,6 +54,16 @@ - (void)viewDidLoad
[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;
Expand Down