Skip to content

Commit

Permalink
Add recursive description debugging method to ASLayout (facebookarchi…
Browse files Browse the repository at this point in the history
…ve#1975)

* Add recursiveDescription debugging method

* Add recursive description implementation

* Add LayoutableObject to ASLayout description
  • Loading branch information
levi authored and appleguy committed Jul 24, 2016
1 parent 6ed5d4a commit 304df12
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
9 changes: 9 additions & 0 deletions AsyncDisplayKit/Layout/ASLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,13 @@ extern BOOL CGPointIsNull(CGPoint point);

@end

@interface ASLayout (Debugging)

/**
* Recrusively output the description of the layout tree.
*/
- (NSString *)recursiveDescription;

@end

NS_ASSUME_NONNULL_END
46 changes: 40 additions & 6 deletions AsyncDisplayKit/Layout/ASLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ extern BOOL CGPointIsNull(CGPoint point)
return isnan(point.x) && isnan(point.y);
}

/**
* Creates an defined number of " |" indent blocks for the recursive description.
*/
static inline NSString * descriptionIndents(NSUInteger indents)
{
NSMutableString *description = [NSMutableString string];
for (NSUInteger i = 0; i < indents; i++) {
[description appendString:@" |"];
}
if (indents > 0) {
[description appendString:@" "];
}
return description;
}

@interface ASLayout ()

/**
Expand Down Expand Up @@ -139,12 +154,6 @@ + (instancetype)layoutWithLayout:(ASLayout *)layout position:(CGPoint)position
sublayouts:layout.sublayouts];
}

- (NSString *)description
{
return [NSString stringWithFormat:@"<<ASLayout: %p>, position = %@; size = %@; constrainedSizeRange = %@>",
self, NSStringFromCGPoint(self.position), NSStringFromCGSize(self.size), NSStringFromASSizeRange(self.constrainedSizeRange)];
}

#pragma mark - Layout Flattening

- (ASLayout *)filteredNodeLayoutTree
Expand Down Expand Up @@ -218,4 +227,29 @@ - (CGRect)frame
return subnodeFrame;
}

#pragma mark - Description

- (NSString *)description
{
return [NSString stringWithFormat:@"<<ASLayout: %p>, layoutable = %@, position = %@; size = %@; constrainedSizeRange = %@>",
self, self.layoutableObject, NSStringFromCGPoint(self.position), NSStringFromCGSize(self.size), NSStringFromASSizeRange(self.constrainedSizeRange)];
}

- (NSString *)recursiveDescription
{
return [self _recursiveDescriptionForLayout:self level:0];
}

- (NSString *)_recursiveDescriptionForLayout:(ASLayout *)layout level:(NSUInteger)level
{
NSMutableString *description = [NSMutableString string];
[description appendString:descriptionIndents(level)];
[description appendString:[layout description]];
for (ASLayout *sublayout in layout.sublayouts) {
[description appendString:@"\n"];
[description appendString:[self _recursiveDescriptionForLayout:sublayout level:level + 1]];
}
return description;
}

@end

0 comments on commit 304df12

Please sign in to comment.