Skip to content

Commit

Permalink
iOS: Introduced ComponentDescriptorFactory to provide app specific co…
Browse files Browse the repository at this point in the history
…mponent 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
  • Loading branch information
fkgozali authored and facebook-github-bot committed May 19, 2018
1 parent 67ec849 commit 0afc70b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
1 change: 1 addition & 0 deletions RNTester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target 'RNTester' do
'RCTBlob',
'RCTCameraRoll',
'RCTFabric',
'RCTFabricSample', # This is RNTesterPods specific sample.
'RCTGeolocation',
'RCTImage',
'RCTLinkingIOS',
Expand Down
10 changes: 8 additions & 2 deletions RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 `../`)
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions React.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
23 changes: 23 additions & 0 deletions ReactCommon/fabric/sample/SampleComponentDescriptorFactor.cpp
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions ReactCommon/fabric/uimanager/ComponentDescriptorFactory.h
Original file line number Diff line number Diff line change
@@ -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
9 changes: 2 additions & 7 deletions ReactCommon/fabric/uimanager/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0afc70b

Please sign in to comment.