@@ -48,8 +48,11 @@ - (void)_staticInitialize;
4848
4949@end
5050
51- // #define LOG(...) NSLog(__VA_ARGS__)
52- #define LOG (...)
51+ #if ASDisplayNodeLoggingEnabled
52+ #define LOG (...) NSLog (__VA_ARGS__)
53+ #else
54+ #define LOG (...)
55+ #endif
5356
5457// Conditionally time these scopes to our debug ivars (only exist in debug/profile builds)
5558#if TIME_DISPLAYNODE_OPS
@@ -1078,19 +1081,54 @@ - (void)__layout
10781081 ASDisplayNodeAssertMainThread ();
10791082 ASDN::MutexLocker l (_propertyLock);
10801083 CGRect bounds = self.bounds ;
1081- if (CGRectEqualToRect (bounds, CGRectZero)) {
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.
1084+
1085+ [self measureNodeWithBoundsIfNecessary: bounds];
1086+
1087+ // Performing layout on a zero-bounds view often results in frame calculations
1088+ // with negative sizes after applying margins, which will cause
1089+ // measureWithSizeRange: on subnodes to assert.
1090+ if (!CGRectEqualToRect (bounds, CGRectZero)) {
1091+ _placeholderLayer.frame = bounds;
1092+ [self layout ];
1093+ [self layoutDidFinish ];
1094+ }
1095+ }
1096+
1097+ - (void )measureNodeWithBoundsIfNecessary : (CGRect)bounds
1098+ {
1099+ // Normally measure will be called before layout occurs. If this doesn't happen, nothing is going to call it at all.
1100+ // We simply call measureWithSizeRange: using a size range equal to whatever bounds were provided to that element or
1101+ // try to measure the node with the largest size as possible
1102+ if (self.supernode == nil && !self.supportsRangeManagedInterfaceState && !_flags.isMeasured ) {
1103+ if (CGRectEqualToRect (bounds, CGRectZero)) {
1104+ LOG (@" Warning: No size given for node before node was trying to layout itself: %@ . Please provide a frame for the node." , self);
1105+ } else {
1106+ [self measureWithSizeRange: ASSizeRangeMake (CGSizeZero, bounds.size)];
1107+ }
1108+ }
1109+ }
1110+
1111+ - (void )layout
1112+ {
1113+ ASDisplayNodeAssertMainThread ();
1114+
1115+ if (!_flags.isMeasured ) {
10851116 return ;
10861117 }
1087- _placeholderLayer.frame = bounds;
1088- [self layout ];
1089- [self layoutDidFinish ];
1118+
1119+ [self __layoutSublayouts ];
1120+ }
1121+
1122+ - (void )__layoutSublayouts
1123+ {
1124+ for (ASLayout *subnodeLayout in _layout.immediateSublayouts ) {
1125+ ((ASDisplayNode *)subnodeLayout.layoutableObject ).frame = [subnodeLayout frame ];
1126+ }
10901127}
10911128
10921129- (void )layoutDidFinish
10931130{
1131+ // Hook for subclasses
10941132}
10951133
10961134- (CATransform3D)_transformToAncestor : (ASDisplayNode *)ancestor
@@ -2377,24 +2415,6 @@ - (void)applyLayout:(ASLayout *)layout
23772415 }
23782416}
23792417
2380- - (void )layout
2381- {
2382- ASDisplayNodeAssertMainThread ();
2383-
2384- if (!_flags.isMeasured ) {
2385- return ;
2386- }
2387-
2388- [self __layoutSublayouts ];
2389- }
2390-
2391- - (void )__layoutSublayouts
2392- {
2393- for (ASLayout *subnodeLayout in _layout.immediateSublayouts ) {
2394- ((ASDisplayNode *)subnodeLayout.layoutableObject ).frame = [subnodeLayout frame ];
2395- }
2396- }
2397-
23982418- (void )displayWillStart
23992419{
24002420 ASDisplayNodeAssertMainThread ();
0 commit comments