Introduce CKMountable protocol

Summary:
- Introduce new base protocol `CKMountable`
  - Contains Layout & Mount methods that have been extracted from `CKComponent`
  - This will allows us to introduce a new lighter version of `CKComponent`, which doesn't rely on Scope/State/Controllers/etc
- Refactor `CKComponentLayout` to work with `CKMountable` instead of `CKComponent`, which will allows us to interop between `CKComponent` and a new type of components.
- Refactor the codebase to support this change

Reviewed By: kevin0571

Differential Revision: D17668253

fbshipit-source-id: 13db5ff4acb37b338e291ca2dd7d67cd25dbc6d2
This commit is contained in:
Kfir Schindelhaim
2019-10-02 08:18:22 -07:00
committed by Facebook Github Bot
parent 9bad9ba976
commit 52976f1ee3

View File

@@ -51,17 +51,19 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo
return cachedWrapper; return cachedWrapper;
} }
} }
CKComponentReuseWrapper *reuseWrapper = CKAnalyticsListenerHelpers::GetReusedNodes(layout.component); // TODO: Add support for `CKMountable` components.
CKComponent *component = (CKComponent *)layout.component;
CKComponentReuseWrapper *reuseWrapper = CKAnalyticsListenerHelpers::GetReusedNodes(component);
// Create a new layout wrapper. // Create a new layout wrapper.
SKComponentLayoutWrapper *const wrapper = SKComponentLayoutWrapper *const wrapper =
[[SKComponentLayoutWrapper alloc] initWithLayout:layout [[SKComponentLayoutWrapper alloc] initWithLayout:layout
position:CGPointMake(0, 0) position:CGPointMake(0, 0)
parentKey:[NSString stringWithFormat: @"%d.", layout.component.treeNode.nodeIdentifier] parentKey:[NSString stringWithFormat: @"%d.", component.treeNode.nodeIdentifier]
reuseWrapper:reuseWrapper reuseWrapper:reuseWrapper
rootNode: root]; rootNode: root];
// Cache the result. // Cache the result.
if (layout.component) { if (component) {
objc_setAssociatedObject(layout.component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC); objc_setAssociatedObject(component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} }
return wrapper; return wrapper;
} }
@@ -74,7 +76,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo
{ {
if (self = [super init]) { if (self = [super init]) {
_rootNode = node; _rootNode = node;
_component = layout.component; _component = (CKComponent *)layout.component;
_size = layout.size; _size = layout.size;
_position = position; _position = position;
_identifier = [parentKey stringByAppendingString:layout.component ? NSStringFromClass([layout.component class]) : @"(null)"]; _identifier = [parentKey stringByAppendingString:layout.component ? NSStringFromClass([layout.component class]) : @"(null)"];
@@ -99,7 +101,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo
rootNode:node rootNode:node
]; ];
childWrapper->_isFlexboxChild = [_component isKindOfClass:[CKFlexboxComponent class]]; childWrapper->_isFlexboxChild = [_component isKindOfClass:[CKFlexboxComponent class]];
childWrapper->_flexboxChild = findFlexboxLayoutParams(_component, child.layout.component); childWrapper->_flexboxChild = findFlexboxLayoutParams(_component, (CKComponent *)child.layout.component);
_children.push_back(childWrapper); _children.push_back(childWrapper);
} }
} }