Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 1b07cab

Browse files
committed
Merge pull request #1717 from levi/revertAutomaticMeasure
Revert "Merge pull request #1673 from maicki/AddAutomaticMeasureBeforeLayout"
2 parents dfaf3b9 + 2052382 commit 1b07cab

File tree

4 files changed

+43
-71
lines changed

4 files changed

+43
-71
lines changed

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#import <AsyncDisplayKit/ASAsciiArtBoxCreator.h>
1616
#import <AsyncDisplayKit/ASLayoutable.h>
1717

18-
#define ASDisplayNodeLoggingEnabled 0
19-
2018
@class ASDisplayNode;
2119

2220
/**

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ - (void)_staticInitialize;
4848

4949
@end
5050

51-
#if ASDisplayNodeLoggingEnabled
52-
#define LOG(...) NSLog(__VA_ARGS__)
53-
#else
54-
#define LOG(...)
55-
#endif
51+
//#define LOG(...) NSLog(__VA_ARGS__)
52+
#define LOG(...)
5653

5754
// Conditionally time these scopes to our debug ivars (only exist in debug/profile builds)
5855
#if TIME_DISPLAYNODE_OPS
@@ -1076,60 +1073,19 @@ - (void)__layout
10761073
ASDisplayNodeAssertMainThread();
10771074
ASDN::MutexLocker l(_propertyLock);
10781075
CGRect bounds = self.bounds;
1079-
1080-
[self measureNodeWithBoundsIfNecessary:bounds];
1081-
1082-
// Performing layout on a zero-bounds view often results in frame calculations
1083-
// with negative sizes after applying margins, which will cause
1084-
// measureWithSizeRange: on subnodes to assert.
1085-
if (!CGRectEqualToRect(bounds, CGRectZero)) {
1086-
// Handle placeholder layer creation in case the size of the node changed after the initial placeholder layer
1087-
// was created
1088-
if ([self _shouldHavePlaceholderLayer]) {
1089-
[self _setupPlaceholderLayerIfNeeded];
1090-
}
1091-
_placeholderLayer.frame = bounds;
1092-
1093-
[self layout];
1094-
[self layoutDidFinish];
1095-
}
1096-
}
1097-
1098-
- (void)measureNodeWithBoundsIfNecessary:(CGRect)bounds
1099-
{
1100-
// Normally measure will be called before layout occurs. If this doesn't happen, nothing is going to call it at all.
1101-
// We simply call measureWithSizeRange: using a size range equal to whatever bounds were provided to that element or
1102-
// try to measure the node with the largest size as possible
1103-
if (self.supernode == nil && !self.supportsRangeManagedInterfaceState && [self _hasDirtyLayout] == NO) {
1104-
if (CGRectEqualToRect(bounds, CGRectZero)) {
1105-
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
1106-
} else {
1107-
[self measureWithSizeRange:ASSizeRangeMake(CGSizeZero, bounds.size)];
1108-
}
1109-
}
1110-
}
1111-
1112-
- (void)layout
1113-
{
1114-
ASDisplayNodeAssertMainThread();
1115-
1116-
if ([self _hasDirtyLayout]) {
1076+
if (CGRectEqualToRect(bounds, CGRectZero)) {
1077+
// Performing layout on a zero-bounds view often results in frame calculations
1078+
// with negative sizes after applying margins, which will cause
1079+
// measureWithSizeRange: on subnodes to assert.
11171080
return;
11181081
}
1119-
1120-
[self __layoutSublayouts];
1121-
}
1122-
1123-
- (void)__layoutSublayouts
1124-
{
1125-
for (ASLayout *subnodeLayout in _layout.immediateSublayouts) {
1126-
((ASDisplayNode *)subnodeLayout.layoutableObject).frame = [subnodeLayout frame];
1127-
}
1082+
_placeholderLayer.frame = bounds;
1083+
[self layout];
1084+
[self layoutDidFinish];
11281085
}
11291086

11301087
- (void)layoutDidFinish
11311088
{
1132-
// Hook for subclasses
11331089
}
11341090

11351091
- (CATransform3D)_transformToAncestor:(ASDisplayNode *)ancestor
@@ -2417,6 +2373,24 @@ - (void)applyLayout:(ASLayout *)layout layoutContext:(ASLayoutTransition *)layou
24172373
}
24182374
}
24192375

2376+
- (void)layout
2377+
{
2378+
ASDisplayNodeAssertMainThread();
2379+
2380+
if (![self _hasDirtyLayout]) {
2381+
return;
2382+
}
2383+
2384+
[self __layoutSublayouts];
2385+
}
2386+
2387+
- (void)__layoutSublayouts
2388+
{
2389+
for (ASLayout *subnodeLayout in _layout.immediateSublayouts) {
2390+
((ASDisplayNode *)subnodeLayout.layoutableObject).frame = [subnodeLayout frame];
2391+
}
2392+
}
2393+
24202394
- (void)displayWillStart
24212395
{
24222396
ASDisplayNodeAssertMainThread();

examples/Videos/Sample/ViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
99
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1010
*/
11-
12-
#include <UIKit/UIKit.h>
11+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
12+
#import <AsyncDisplayKit/ASVideoNode.h>
1313

1414
@interface ViewController : UIViewController
1515

examples/Videos/Sample/ViewController.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
*/
1111

1212
#import "ViewController.h"
13-
#import <AsyncDisplayKit/AsyncDisplayKit.h>
13+
#import "ASLayoutSpec.h"
14+
#import "ASStaticLayoutSpec.h"
1415

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

2223
#pragma mark - UIViewController
2324

24-
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
25+
- (void)viewWillAppear:(BOOL)animated
2526
{
26-
self = [super initWithNibName:nil bundle:nil];
27-
if (self) {
27+
[super viewWillAppear:animated];
2828

29-
30-
}
31-
return self;
32-
}
33-
34-
- (void)viewDidLoad
35-
{
36-
[super viewDidLoad];
37-
3829
// Root node for the view controller
3930
_rootNode = [ASDisplayNode new];
40-
_rootNode.frame = self.view.bounds;
4131
_rootNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
4232

4333
ASVideoNode *guitarVideoNode = self.guitarVideoNode;
@@ -64,6 +54,16 @@ - (void)viewDidLoad
6454
[self.view addSubnode:_rootNode];
6555
}
6656

57+
- (void)viewDidLayoutSubviews
58+
{
59+
[super viewDidLayoutSubviews];
60+
61+
// After all subviews are layed out we have to measure it and move the root node to the right place
62+
CGSize viewSize = self.view.bounds.size;
63+
[self.rootNode measureWithSizeRange:ASSizeRangeMake(viewSize, viewSize)];
64+
[self.rootNode setNeedsLayout];
65+
}
66+
6767
#pragma mark - Getter / Setter
6868

6969
- (ASVideoNode *)guitarVideoNode;

0 commit comments

Comments
 (0)