From 7a11c4b32beff04c753d419531fe98c2ae13fe2e Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Wed, 15 Mar 2017 18:20:19 +0000 Subject: [PATCH] Fix recursive description of ASDisplayNode (#3186) - Before this commit: - Bridged properties are accessed to construct a recursive description without considering thread affinity. - We have multiple methods that does the same thing: generates a debug description. - After this commit: - Bridged properties are accessed without triggering thread affinity assertions. - We have only one method that provides debug description of a node. It is then used to construct a recursive description. --- Source/ASDisplayNode.mm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/ASDisplayNode.mm b/Source/ASDisplayNode.mm index 069d106a7b..0e44eb5fd4 100644 --- a/Source/ASDisplayNode.mm +++ b/Source/ASDisplayNode.mm @@ -3972,10 +3972,13 @@ ASDISPLAYNODE_INLINE BOOL nodeIsInRasterizedTree(ASDisplayNode *node) { } if (_view != nil) { + [result addObject:@{ @"alpha" : @(_view.alpha) }]; [result addObject:@{ @"frame" : [NSValue valueWithCGRect:_view.frame] }]; } else if (_layer != nil) { + [result addObject:@{ @"alpha" : @(_layer.opacity) }]; [result addObject:@{ @"frame" : [NSValue valueWithCGRect:_layer.frame] }]; } else if (_pendingViewState != nil) { + [result addObject:@{ @"alpha" : @(_pendingViewState.alpha) }]; [result addObject:@{ @"frame" : [NSValue valueWithCGRect:_pendingViewState.frame] }]; } @@ -4000,6 +4003,11 @@ ASDISPLAYNODE_INLINE BOOL nodeIsInRasterizedTree(ASDisplayNode *node) { } else if (_layerBlock != nil) { [result addObject:@{ @"layerBlock" : _layerBlock }]; } + +#if TIME_DISPLAYNODE_OPS + NSString *creationTypeString = [NSString stringWithFormat:@"cr8:%.2lfms dl:%.2lfms ap:%.2lfms ad:%.2lfms", 1000 * _debugTimeToCreateView, 1000 * _debugTimeForDidLoad, 1000 * _debugTimeToApplyPendingState, 1000 * _debugTimeToAddSubnodeViews]; + [result addObject:@{ @"creationTypeString" : creationTypeString }]; +#endif return result; } @@ -4140,16 +4148,6 @@ ASLayoutElementStyleExtensibilityForwarding @implementation ASDisplayNode (Debugging) -- (NSString *)descriptionForRecursiveDescription -{ - NSString *creationTypeString = nil; -#if TIME_DISPLAYNODE_OPS - creationTypeString = [NSString stringWithFormat:@"cr8:%.2lfms dl:%.2lfms ap:%.2lfms ad:%.2lfms", 1000 * _debugTimeToCreateView, 1000 * _debugTimeForDidLoad, 1000 * _debugTimeToApplyPendingState, 1000 * _debugTimeToAddSubnodeViews]; -#endif - - return [NSString stringWithFormat:@"<%@ alpha:%.2f isLayerBacked:%d frame:%@ %@>", self.description, self.alpha, self.isLayerBacked, NSStringFromCGRect(self.frame), creationTypeString]; -} - - (NSString *)displayNodeRecursiveDescription { return [self _recursiveDescriptionHelperWithIndent:@""]; @@ -4157,7 +4155,7 @@ ASLayoutElementStyleExtensibilityForwarding - (NSString *)_recursiveDescriptionHelperWithIndent:(NSString *)indent { - NSMutableString *subtree = [[[indent stringByAppendingString: self.descriptionForRecursiveDescription] stringByAppendingString:@"\n"] mutableCopy]; + NSMutableString *subtree = [[[indent stringByAppendingString:self.debugDescription] stringByAppendingString:@"\n"] mutableCopy]; for (ASDisplayNode *n in self.subnodes) { [subtree appendString:[n _recursiveDescriptionHelperWithIndent:[indent stringByAppendingString:@" | "]]]; }