From 52976f1ee35004bb96d9ef24ff79e6cab558d182 Mon Sep 17 00:00:00 2001 From: Kfir Schindelhaim Date: Wed, 2 Oct 2019 08:18:22 -0700 Subject: [PATCH] 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 --- .../SKComponentLayoutWrapper.mm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm index 33ea42521..39d012e78 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm @@ -51,17 +51,19 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo 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. SKComponentLayoutWrapper *const wrapper = [[SKComponentLayoutWrapper alloc] initWithLayout:layout position:CGPointMake(0, 0) - parentKey:[NSString stringWithFormat: @"%d.", layout.component.treeNode.nodeIdentifier] + parentKey:[NSString stringWithFormat: @"%d.", component.treeNode.nodeIdentifier] reuseWrapper:reuseWrapper rootNode: root]; // Cache the result. - if (layout.component) { - objc_setAssociatedObject(layout.component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + if (component) { + objc_setAssociatedObject(component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return wrapper; } @@ -74,7 +76,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo { if (self = [super init]) { _rootNode = node; - _component = layout.component; + _component = (CKComponent *)layout.component; _size = layout.size; _position = position; _identifier = [parentKey stringByAppendingString:layout.component ? NSStringFromClass([layout.component class]) : @"(null)"]; @@ -99,7 +101,7 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo rootNode:node ]; 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); } }