Show mounted ComponentKit views in Flipper

Summary:
Before this diff, Flipper showed *leaf* views created by ComponentKit, but not any intermediate views. Now we show both.

A new node type `SKComponentMountedView` is used for this purpose. Its descriptor `SKComponentMountedViewDescriptor` mostly delegates to its view's descriptor, but redirects back into ComponentKit for children.

Reviewed By: Andrey-Mishanin

Differential Revision: D21130997

fbshipit-source-id: b3c12ea7cc1200962b3ba7c269c48d68b1809948
This commit is contained in:
Adam Ernst
2020-04-21 11:51:02 -07:00
committed by Facebook GitHub Bot
parent 756987e4bf
commit d0803ecd56
8 changed files with 274 additions and 50 deletions

View File

@@ -18,12 +18,13 @@
#import <ComponentKit/CKInspectableView.h>
#import "CKComponent+Sonar.h"
#import "SKComponentMountedView.h"
static char const kLayoutWrapperKey = ' ';
static CKFlexboxComponentChild findFlexboxLayoutParams(
CKComponent* parent,
CKComponent* child) {
static CK::Optional<CKFlexboxComponentChild> findFlexboxLayoutParams(
id<CKMountable> parent,
id<CKMountable> child) {
if ([parent isKindOfClass:[CKFlexboxComponent class]]) {
static Ivar ivar =
class_getInstanceVariable([CKFlexboxComponent class], "_children");
@@ -42,7 +43,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
}
}
return {};
return CK::none;
}
@implementation SKComponentLayoutWrapper
@@ -66,6 +67,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
SKComponentLayoutWrapper* const wrapper = [[SKComponentLayoutWrapper alloc]
initWithLayout:layout
position:CGPointMake(0, 0)
flexboxChild:CK::none
parentKey:[NSString
stringWithFormat:@"%@%d.",
parentKey,
@@ -85,6 +87,8 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
- (instancetype)initWithLayout:(const CKComponentLayout&)layout
position:(CGPoint)position
flexboxChild:
(CK::Optional<CKFlexboxComponentChild>)flexboxChild
parentKey:(NSString*)parentKey
reuseWrapper:(CKComponentReuseWrapper*)reuseWrapper
rootNode:(id<CKInspectableView>)node {
@@ -93,6 +97,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
_component = (CKComponent*)layout.component;
_size = layout.size;
_position = position;
_flexboxChild = flexboxChild;
_identifier = [parentKey stringByAppendingString:layout.component
? layout.component.className
: @"(null)"];
@@ -105,6 +110,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
}
}
std::vector<SKComponentLayoutWrapper*> childComponents;
if (layout.children != nullptr) {
int index = 0;
for (const auto& child : *layout.children) {
@@ -115,17 +121,26 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(
[[SKComponentLayoutWrapper alloc]
initWithLayout:child.layout
position:child.position
flexboxChild:findFlexboxLayoutParams(
_component, child.layout.component)
parentKey:[_identifier
stringByAppendingFormat:@"[%d].", index++]
reuseWrapper:reuseWrapper
rootNode:node];
childWrapper->_isFlexboxChild =
[_component isKindOfClass:[CKFlexboxComponent class]];
childWrapper->_flexboxChild = findFlexboxLayoutParams(
_component, (CKComponent*)child.layout.component);
_children.push_back(childWrapper);
childComponents.push_back(childWrapper);
}
}
UIView* mountedView = _component.mountedView;
if (mountedView && !childComponents.empty()) {
_children = SKMountedViewChild{[[SKComponentMountedView alloc]
initWithView:mountedView
children:childComponents]};
} else if (mountedView) {
_children = SKLeafViewChild{mountedView}; // leaf view
} else {
_children = childComponents;
}
}
return self;