Workaround for ensuring creation of visualizerNode for ALL layoutspecs

This commit is contained in:
Hannah Troisi
2016-03-21 21:01:14 -07:00
parent fa7d6aa120
commit 531c0fa718
8 changed files with 33 additions and 7 deletions

View File

@@ -31,8 +31,10 @@
#import "ASLayoutSpec.h"
#import "ASCellNode.h"
#import "ASLayoutSpec+Debug.h" // FIXME: remove later
#import "ASStaticLayoutSpec.h" // FIXME: remove later
NSInteger const ASDefaultDrawingPriority = ASDefaultTransactionPriority;
NSString * const ASRenderingEngineDidDisplayScheduledNodesNotification = @"ASRenderingEngineDidDisplayScheduledNodes";
NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp = @"ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp";
@@ -1791,12 +1793,15 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
{
ASDN::MutexLocker l(_propertyLock);
if (_methodOverrides & ASDisplayNodeMethodOverrideLayoutSpecThatFits) {
ASLayoutSpec *layoutSpec = [self layoutSpecThatFits:constrainedSize];
if (ASHierarchyStateIncludesVisualizeLayoutSpecs(_hierarchyState)) {
[layoutSpec recursivelySetShouldVisualize:YES];
// [layoutSpec recursivelySetShouldVisualize:YES];
[ASLayoutSpec setShouldVisualizeLayoutSpecs2:YES];
}
ASStaticLayoutSpec *staticSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[[self layoutSpecThatFits:constrainedSize]]];
ASLayoutSpec *layoutSpec = staticSpec;
layoutSpec.isMutable = NO;
ASLayout *layout = [layoutSpec measureWithSizeRange:constrainedSize];
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
@@ -1804,6 +1809,12 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
layout.position = CGPointZero;
layout = [ASLayout layoutWithLayoutableObject:self size:layout.size sublayouts:@[layout]];
}
if (ASHierarchyStateIncludesVisualizeLayoutSpecs(_hierarchyState)) {
[ASLayoutSpec setShouldVisualizeLayoutSpecs2:NO];
}
return [layout flattenedLayoutUsingPredicateBlock:^BOOL(ASLayout *evaluatedLayout) {
if (self.usesImplicitHierarchyManagement) {
return ASObjectIsEqual(layout, evaluatedLayout) == NO && [evaluatedLayout.layoutableObject isKindOfClass:[ASDisplayNode class]];

View File

@@ -11,6 +11,8 @@
@interface ASLayoutSpec (Debugging2)
+ (BOOL)shouldVisualizeLayoutSpecs2;
+ (void)setShouldVisualizeLayoutSpecs2:(BOOL)shouldVisualizeLayoutSpecs;
@end

View File

@@ -13,7 +13,16 @@
@implementation ASLayoutSpec (Debugging2)
static BOOL __shouldVisualizeLayoutSpecs = NO;
+ (BOOL)shouldVisualizeLayoutSpecs2
{
return __shouldVisualizeLayoutSpecs;
}
+ (void)setShouldVisualizeLayoutSpecs2:(BOOL)shouldVisualizeLayoutSpecs
{
__shouldVisualizeLayoutSpecs = shouldVisualizeLayoutSpecs;
}
@end
@@ -36,8 +45,8 @@
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
insetSpec.shouldVisualize = YES;
self.layoutSpec.shouldVisualize = YES;
insetSpec.neverShouldVisualize = YES;
self.layoutSpec.neverShouldVisualize = YES;
UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 10, 10);
insetSpec.insets = insets;
insetSpec.child = self.layoutSpec;

View File

@@ -31,6 +31,7 @@ typedef struct {
CGSize min;
CGSize max;
int32_t transitionID;
BOOL visualize;
} ASSizeRange;
extern ASRelativeDimension const ASRelativeDimensionUnconstrained;

View File

@@ -101,6 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
// FIXME:
@property (nonatomic, assign) BOOL shouldVisualize;
@property (nonatomic, assign) BOOL neverShouldVisualize;
- (void)recursivelySetShouldVisualize:(BOOL)visualize;
@end

View File

@@ -58,7 +58,7 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey";
- (id<ASLayoutable>)finalLayoutable
{
return self;
return ((!self.neverShouldVisualize && [ASLayoutSpec shouldVisualizeLayoutSpecs2] ) ? [[ASLayoutSpecVisualizerNode alloc] initWithLayoutSpec:self] : self);
}
- (void)recursivelySetShouldVisualize:(BOOL)visualize

View File

@@ -36,6 +36,9 @@
lpgr.minimumPressDuration = 0.0;
lpgr.allowableMovement = CGFLOAT_MAX;
[_resizeHandle.view addGestureRecognizer:lpgr];
[self shouldVisualizeLayoutSpecs:YES];
}
return self;

View File

@@ -34,7 +34,6 @@
_individualColorNode = [[ColorNode alloc] init];
_individualColorNode.backgroundColor = [UIColor orangeColor];
[self shouldVisualizeLayoutSpecs:YES];
}
return self;