Skip to content

Commit 0afc70b

Browse files
fkgozalifacebook-github-bot
authored andcommitted
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
1 parent 67ec849 commit 0afc70b

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

RNTester/Podfile

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target 'RNTester' do
1616
'RCTBlob',
1717
'RCTCameraRoll',
1818
'RCTFabric',
19+
'RCTFabricSample', # This is RNTesterPods specific sample.
1920
'RCTGeolocation',
2021
'RCTImage',
2122
'RCTLinkingIOS',

RNTester/Podfile.lock

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PODS:
2727
- React/fabric/core (= 1000.0.0)
2828
- React/fabric/debug (= 1000.0.0)
2929
- React/fabric/graphics (= 1000.0.0)
30+
- React/fabric/scrollview (= 1000.0.0)
3031
- React/fabric/text (= 1000.0.0)
3132
- React/fabric/textlayoutmanager (= 1000.0.0)
3233
- React/fabric/uimanager (= 1000.0.0)
@@ -39,6 +40,8 @@ PODS:
3940
- Folly (= 2016.10.31.00)
4041
- React/fabric/graphics (1000.0.0):
4142
- Folly (= 2016.10.31.00)
43+
- React/fabric/scrollview (1000.0.0):
44+
- Folly (= 2016.10.31.00)
4245
- React/fabric/text (1000.0.0):
4346
- Folly (= 2016.10.31.00)
4447
- React/fabric/textlayoutmanager (1000.0.0):
@@ -67,6 +70,8 @@ PODS:
6770
- Folly (= 2016.10.31.00)
6871
- React/Core
6972
- React/fabric
73+
- React/RCTFabricSample (1000.0.0):
74+
- Folly (= 2016.10.31.00)
7075
- React/RCTGeolocation (1000.0.0):
7176
- React/Core
7277
- React/RCTImage (1000.0.0):
@@ -103,6 +108,7 @@ DEPENDENCIES:
103108
- React/RCTBlob (from `../`)
104109
- React/RCTCameraRoll (from `../`)
105110
- React/RCTFabric (from `../`)
111+
- React/RCTFabricSample (from `../`)
106112
- React/RCTGeolocation (from `../`)
107113
- React/RCTImage (from `../`)
108114
- React/RCTLinkingIOS (from `../`)
@@ -135,9 +141,9 @@ SPEC CHECKSUMS:
135141
DoubleConversion: e22e0762848812a87afd67ffda3998d9ef29170c
136142
Folly: 9a8eea4725a0b6ba3256ebf206c21e352c23abf8
137143
glog: 1de0bb937dccdc981596d3b5825ebfb765017ded
138-
React: 3d56cdd885ecc0f2f3534b2f54a11cf9707229fb
144+
React: 0a0271674c3a6772a89a6606f337ed8db583abc0
139145
yoga: bdd268c5812f00bdb52cc2b58f129797e97935eb
140146

141-
PODFILE CHECKSUM: 1a96172007b66aa74825c234f17139dd9c3d3cd7
147+
PODFILE CHECKSUM: b28ea97efdc10f046a3a1b7b455c1e18a39cb10a
142148

143149
COCOAPODS: 1.5.2

React.podspec

+10
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ Pod::Spec.new do |s|
218218
end
219219
end
220220

221+
# Fabric sample target for sample app purpose.
222+
s.subspec "RCTFabricSample" do |ss|
223+
ss.dependency "Folly", folly_version
224+
ss.compiler_flags = folly_compiler_flags
225+
ss.source_files = "ReactCommon/fabric/sample/**/*.{cpp,h}"
226+
ss.exclude_files = "**/tests/*"
227+
ss.header_dir = "fabric/sample"
228+
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Folly\"" }
229+
end
230+
221231
s.subspec "ART" do |ss|
222232
ss.dependency "React/Core"
223233
ss.source_files = "Libraries/ART/**/*.{h,m}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <fabric/uimanager/ComponentDescriptorFactory.h>
9+
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
10+
11+
namespace facebook {
12+
namespace react {
13+
14+
/**
15+
* This is a sample implementation. Each app should provide its own.
16+
*/
17+
SharedComponentDescriptorRegistry ComponentDescriptorFactory::buildRegistry() {
18+
auto registry = std::make_shared<ComponentDescriptorRegistry>();
19+
return registry;
20+
}
21+
22+
} // namespace react
23+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <memory>
11+
12+
#include <fabric/core/ComponentDescriptor.h>
13+
14+
#include "ComponentDescriptorRegistry.h"
15+
16+
namespace facebook {
17+
namespace react {
18+
19+
/**
20+
* A factory to provide hosting app specific set of ComponentDescriptor's.
21+
* Each app must provide an implementation of the static class method which
22+
* should register its specific set of supported components.
23+
*/
24+
class ComponentDescriptorFactory {
25+
26+
public:
27+
static SharedComponentDescriptorRegistry buildRegistry();
28+
};
29+
30+
} // namespace react
31+
} // namespace facebook

ReactCommon/fabric/uimanager/Scheduler.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313
#include <fabric/view/ViewProps.h>
1414
#include <fabric/view/ViewShadowNode.h>
1515

16+
#include "ComponentDescriptorFactory.h"
1617
#include "Differentiator.h"
1718

1819
namespace facebook {
1920
namespace react {
2021

2122
Scheduler::Scheduler() {
22-
auto componentDescriptorRegistry = std::make_shared<ComponentDescriptorRegistry>();
23-
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ViewComponentDescriptor>());
24-
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ScrollViewComponentDescriptor>());
25-
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<ParagraphComponentDescriptor>());
26-
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<TextComponentDescriptor>());
27-
componentDescriptorRegistry->registerComponentDescriptor(std::make_shared<RawTextComponentDescriptor>());
28-
23+
auto componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry();
2924
uiManager_ = std::make_shared<FabricUIManager>(componentDescriptorRegistry);
3025
uiManager_->setDelegate(this);
3126
}

0 commit comments

Comments
 (0)