iOS: Introduced ComponentDescriptorFactory to provide app specific component registry

Summary: Each app has its own set of components to support, so this mechanism allows each of them to customize the set. Core library only provides the signature (.h file) without any impl.

Reviewed By: shergin

Differential Revision: D8065360

fbshipit-source-id: c123397afda678e84f1d1fa41a6393f25b2c15e1
This commit is contained in:
Kevin Gozali 2018-05-18 19:44:34 -07:00 committed by Facebook Github Bot
parent 67ec8498f7
commit 0afc70b24a
6 changed files with 75 additions and 9 deletions

View File

@ -16,6 +16,7 @@ target 'RNTester' do
'RCTBlob',
'RCTCameraRoll',
'RCTFabric',
'RCTFabricSample', # This is RNTesterPods specific sample.
'RCTGeolocation',
'RCTImage',
'RCTLinkingIOS',

View File

@ -27,6 +27,7 @@ PODS:
- React/fabric/core (= 1000.0.0)
- React/fabric/debug (= 1000.0.0)
- React/fabric/graphics (= 1000.0.0)
- React/fabric/scrollview (= 1000.0.0)
- React/fabric/text (= 1000.0.0)
- React/fabric/textlayoutmanager (= 1000.0.0)
- React/fabric/uimanager (= 1000.0.0)
@ -39,6 +40,8 @@ PODS:
- Folly (= 2016.10.31.00)
- React/fabric/graphics (1000.0.0):
- Folly (= 2016.10.31.00)
- React/fabric/scrollview (1000.0.0):
- Folly (= 2016.10.31.00)
- React/fabric/text (1000.0.0):
- Folly (= 2016.10.31.00)
- React/fabric/textlayoutmanager (1000.0.0):
@ -67,6 +70,8 @@ PODS:
- Folly (= 2016.10.31.00)
- React/Core
- React/fabric
- React/RCTFabricSample (1000.0.0):
- Folly (= 2016.10.31.00)
- React/RCTGeolocation (1000.0.0):
- React/Core
- React/RCTImage (1000.0.0):
@ -103,6 +108,7 @@ DEPENDENCIES:
- React/RCTBlob (from `../`)
- React/RCTCameraRoll (from `../`)
- React/RCTFabric (from `../`)
- React/RCTFabricSample (from `../`)
- React/RCTGeolocation (from `../`)
- React/RCTImage (from `../`)
- React/RCTLinkingIOS (from `../`)
@ -135,9 +141,9 @@ SPEC CHECKSUMS:
DoubleConversion: e22e0762848812a87afd67ffda3998d9ef29170c
Folly: 9a8eea4725a0b6ba3256ebf206c21e352c23abf8
glog: 1de0bb937dccdc981596d3b5825ebfb765017ded
React: 3d56cdd885ecc0f2f3534b2f54a11cf9707229fb
React: 0a0271674c3a6772a89a6606f337ed8db583abc0
yoga: bdd268c5812f00bdb52cc2b58f129797e97935eb
PODFILE CHECKSUM: 1a96172007b66aa74825c234f17139dd9c3d3cd7
PODFILE CHECKSUM: b28ea97efdc10f046a3a1b7b455c1e18a39cb10a
COCOAPODS: 1.5.2

View File

@ -218,6 +218,16 @@ Pod::Spec.new do |s|
end
end
# Fabric sample target for sample app purpose.
s.subspec "RCTFabricSample" do |ss|
ss.dependency "Folly", folly_version
ss.compiler_flags = folly_compiler_flags
ss.source_files = "ReactCommon/fabric/sample/**/*.{cpp,h}"
ss.exclude_files = "**/tests/*"
ss.header_dir = "fabric/sample"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Folly\"" }
end
s.subspec "ART" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/ART/**/*.{h,m}"

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <fabric/uimanager/ComponentDescriptorFactory.h>
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
namespace facebook {
namespace react {
/**
* This is a sample implementation. Each app should provide its own.
*/
SharedComponentDescriptorRegistry ComponentDescriptorFactory::buildRegistry() {
auto registry = std::make_shared<ComponentDescriptorRegistry>();
return registry;
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <fabric/core/ComponentDescriptor.h>
#include "ComponentDescriptorRegistry.h"
namespace facebook {
namespace react {
/**
* A factory to provide hosting app specific set of ComponentDescriptor's.
* Each app must provide an implementation of the static class method which
* should register its specific set of supported components.
*/
class ComponentDescriptorFactory {
public:
static SharedComponentDescriptorRegistry buildRegistry();
};
} // namespace react
} // namespace facebook

View File

@ -13,19 +13,14 @@
#include <fabric/view/ViewProps.h>
#include <fabric/view/ViewShadowNode.h>
#include "ComponentDescriptorFactory.h"
#include "Differentiator.h"
namespace facebook {
namespace react {
Scheduler::Scheduler() {
auto componentDescriptorRegistry = std::make_shared<ComponentDescriptorRegistry>();
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ViewComponentDescriptor>());
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ScrollViewComponentDescriptor>());
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ParagraphComponentDescriptor>());
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<TextComponentDescriptor>());
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<RawTextComponentDescriptor>());
auto componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry();
uiManager_ = std::make_shared<FabricUIManager>(componentDescriptorRegistry);
uiManager_->setDelegate(this);
}