Skip to content

Commit

Permalink
Merge pull request facebook#343 from Goom11/master
Browse files Browse the repository at this point in the history
Fixed a bug with pcomponents
  • Loading branch information
natansh committed Aug 8, 2015
2 parents fbab230 + def8f13 commit cc3cfac
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions ComponentKit/Debug/CKComponentHierarchyDebugHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ + (NSString *)componentHierarchyDescriptionForView:(UIView *)view searchUpwards:
withString:indentString
startingAtIndex:0];
} else {
NSString *rootViewDescription = computeDescription(nil, rootView, {0, 0}, {0, 0}, @"", YES);
NSString *rootViewDescription = computeDescription(nil, rootView, CGSizeZero, CGPointZero, @"", YES);
viewAncestorDescription = [NSString stringWithFormat:@"For View: %@", rootViewDescription];
prefix = indentString;
}
Expand Down Expand Up @@ -112,17 +112,20 @@ static NSUInteger depthOfViewInViewHierarchy(UIView *view)
NSArray *orderedAncestors = [[ancestors reverseObjectEnumerator] allObjects];

for (UIView *ancestor in orderedAncestors) {
[description appendString:computeDescription(nil, ancestor, {0, 0}, {0, 0}, prefix, YES)];
[description appendString:computeDescription(nil, ancestor, CGSizeZero, CGPointZero, prefix, YES)];
[prefix appendString:indentString];
}
return description;
}

static NSString *componentAncestorDescriptionForView(UIView *view, const CKComponentLayout &rootLayout, NSString *prefix, BOOL showViews)
static NSString *componentAncestorDescriptionForView(UIView *view,
const CKComponentLayout &rootLayout,
NSString *prefix,
BOOL showViews)
{
CKComponent *component = view.ck_component;
std::deque<CKComponentDescriptionInformation> ancestors;
buildComponentAncestors(rootLayout, component, {0, 0}, ancestors);
buildComponentAncestors(rootLayout, component, CGPointZero, ancestors);
NSMutableString *description = [NSMutableString string];
NSMutableString *currentPrefix = [prefix mutableCopy];
for (auto &descriptionInformation : ancestors) {
Expand All @@ -137,7 +140,10 @@ static NSUInteger depthOfViewInViewHierarchy(UIView *view)
return description;
}

static BOOL buildComponentAncestors(const CKComponentLayout &layout, CKComponent *component, CGPoint position, std::deque<CKComponentDescriptionInformation> &ancestors)
static BOOL buildComponentAncestors(const CKComponentLayout &layout,
CKComponent *component,
CGPoint position,
std::deque<CKComponentDescriptionInformation> &ancestors)
{
CKComponent *layoutComponent = layout.component;
UIView *view = layoutComponent.viewContext.view;
Expand Down Expand Up @@ -169,27 +175,20 @@ static BOOL buildComponentAncestors(const CKComponentLayout &layout, CKComponent
const CKComponentLayout &rootLayout = *rootLayoutFromRootView(rootView);
const CKComponentLayout &layout = *findLayoutForComponent(component, rootLayout);
if (showViews) {
description = recursiveDescriptionForLayout(layout, {0, 0}, @"", showViews);
description = recursiveDescriptionForLayout(layout, CGPointZero, @"", showViews);
} else {
NSString *rootViewDescription = computeDescription(nil, rootView, {0, 0}, {0, 0}, @"", YES);
NSString *rootViewDescription = computeDescription(nil, rootView, CGSizeZero, CGPointZero, @"", YES);
NSString *viewAncestorDescription = [NSString stringWithFormat:@"For View: %@", rootViewDescription];
description = recursiveDescriptionForLayout(layout, {0, 0}, indentString, showViews);
description = recursiveDescriptionForLayout(layout, CGPointZero, indentString, showViews);
description = [viewAncestorDescription stringByAppendingString:description];
}
} else if (showViews) {
description = recursiveDescriptionForView(view, @"");
} else {
description = @"No component found for given view";
description = recursiveDescriptionForView(view, @"", showViews);
}
return description;
}

static NSMutableString *computeDescription(CKComponent *component,
UIView *view,
CGSize size,
CGPoint position,
NSString *prefix,
BOOL showView)
static NSMutableString *computeDescription(CKComponent *component, UIView *view, CGSize size, CGPoint position, NSString *prefix, BOOL showView)
{
NSMutableString *nodeDescription = [NSMutableString string];
if (component) {
Expand All @@ -203,24 +202,35 @@ static BOOL buildComponentAncestors(const CKComponentLayout &layout, CKComponent
return nodeDescription;
}

static NSMutableString *recursiveDescriptionForView(UIView *view, NSString *prefix)
static NSMutableString *recursiveDescriptionForView(UIView *view, NSString *prefix, BOOL showViews)
{
if ([view isKindOfClass:[CKComponentRootView class]]) {
CKComponentRootView *rootView = (CKComponentRootView *)view;
const CKComponentLayout *rootLayout = rootLayoutFromRootView(rootView);
if (rootLayout) {
NSMutableString *description = [NSMutableString string];
[description appendString:computeDescription(nil, rootView, {0, 0}, {0, 0}, prefix, YES)];
[description appendString:recursiveDescriptionForLayout(*rootLayout, {0, 0}, [prefix stringByAppendingString:indentString], YES)];
if (!showViews) {
[description appendString:@"For View: "];
}
// We always get the description of the CKComponentRootView (even if showViews is NO).
[description appendString:computeDescription(nil, rootView, CGSizeZero, CGPointZero, prefix, YES)];
[description appendString:recursiveDescriptionForLayout(*rootLayout,
CGPointZero,
[prefix stringByAppendingString:indentString],
showViews)];
return description;
}
}
// Either the view is not a CKComponentRootView or the view does not have a rootLayout
// Either the view is not a RootView or it does not have a RootLayout.
NSMutableString *description = [NSMutableString string];
description = computeDescription(nil, view, {0, 0}, {0, 0}, prefix, YES);
if (showViews) {
[description appendString:computeDescription(nil, view, CGSizeZero, CGPointZero, prefix, YES)];
}
if (view.subviews) {
// If we are not showing views then we shouldn't increase the prefix.
NSString *newPrefix = showViews ? [prefix stringByAppendingString:indentString] : prefix;
for (UIView *subview in view.subviews) {
[description appendString:recursiveDescriptionForView(subview, [prefix stringByAppendingString:indentString])];
[description appendString:recursiveDescriptionForView(subview, newPrefix, showViews)];
}
}
return description;
Expand All @@ -234,9 +244,10 @@ static BOOL buildComponentAncestors(const CKComponentLayout &layout, CKComponent
return (CKComponentRootView *)view;
}

/* Note: This is fragile code that is being used because ComponentKit is
* currently in the process of transitioning away holding the root layout in
* CKComponentRootView
/**
Note: This is fragile code that is being used because ComponentKit is currently in the process of
transitioning away from holding the root layout in CKComponentRootView. This code should be updated
once the move away from a ck_componentLifecycleManager is done.
*/
static const CKComponentLayout *rootLayoutFromRootView(CKComponentRootView *rootView)
{
Expand Down Expand Up @@ -270,7 +281,10 @@ static BOOL buildComponentAncestors(const CKComponentLayout &layout, CKComponent
return componentLayout;
}

static NSMutableString *recursiveDescriptionForLayout(const CKComponentLayout &layout, CGPoint position, NSString *prefix, BOOL showViews)
static NSMutableString *recursiveDescriptionForLayout(const CKComponentLayout &layout,
CGPoint position,
NSString *prefix,
BOOL showViews)
{
CKComponent *component = layout.component;
NSMutableString *description = computeDescription(component, component.viewContext.view, layout.size, position, prefix, showViews);
Expand Down

0 comments on commit cc3cfac

Please sign in to comment.