diff --git a/Source/ASDisplayNode+Beta.h b/Source/ASDisplayNode+Beta.h index affe99cb2..202dc4b56 100644 --- a/Source/ASDisplayNode+Beta.h +++ b/Source/ASDisplayNode+Beta.h @@ -207,6 +207,12 @@ AS_EXTERN void ASDisplayNodePerformBlockOnEveryYogaChild(ASDisplayNode * _Nullab @end +@interface ASDisplayNode (YogaDebugging) + +- (NSString *)yogaTreeDescription; + +@end + @interface ASLayoutElementStyle (Yoga) - (YGNodeRef)yogaNodeCreateIfNeeded; diff --git a/Source/ASDisplayNode+Yoga.mm b/Source/ASDisplayNode+Yoga.mm index 8f4cfdc63..d7bd83ebd 100644 --- a/Source/ASDisplayNode+Yoga.mm +++ b/Source/ASDisplayNode+Yoga.mm @@ -321,4 +321,20 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize @end +@implementation ASDisplayNode (YogaDebugging) + +- (NSString *)yogaTreeDescription { + return [self _yogaTreeDescription:@""]; +} + +- (NSString *)_yogaTreeDescription:(NSString *)indent { + auto subtree = [NSMutableString stringWithFormat:@"%@%@\n", indent, self.description]; + for (ASDisplayNode *n in self.yogaChildren) { + [subtree appendString:[n _yogaTreeDescription:[indent stringByAppendingString:@"| "]]]; + } + return subtree; +} + +@end + #endif /* YOGA */