Skip to content

Commit 4f9a3bc

Browse files
fkgozalifacebook-github-bot
authored andcommitted
xplat: pass through config object to fabric UIManager layer
Summary: For configuration purpose, pass down config object from the hosting app and use it in UITemplateProcessor. Reviewed By: sahrens Differential Revision: D13290322 fbshipit-source-id: 8bb6d7f5a3f977b873e548e15603259876b46dc8
1 parent 3b6f229 commit 4f9a3bc

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

ReactCommon/fabric/uimanager/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rn_xplat_cxx_library(
5858
"xplat//jsi:JSIDynamic",
5959
"xplat//jsi:jsi",
6060
"xplat//third-party/glog:glog",
61+
react_native_xplat_target("config:config"),
6162
react_native_xplat_target("fabric/components/root:root"),
6263
react_native_xplat_target("fabric/components/view:view"),
6364
react_native_xplat_target("fabric/mounting:mounting"),
@@ -83,6 +84,7 @@ fb_xplat_cxx_test(
8384
"xplat//folly:molly",
8485
"xplat//third-party/gmock:gtest",
8586
":uimanager",
87+
react_native_xplat_target("config:config"),
8688
react_native_xplat_target("fabric/components/activityindicator:activityindicator"),
8789
react_native_xplat_target("fabric/components/image:image"),
8890
react_native_xplat_target("fabric/components/root:root"),

ReactCommon/fabric/uimanager/Scheduler.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ Scheduler::Scheduler(const SharedContextContainer &contextContainer)
2828
runtimeExecutor_ =
2929
contextContainer->getInstance<RuntimeExecutor>("runtime-executor");
3030

31+
reactNativeConfig_ =
32+
contextContainer->getInstance<std::shared_ptr<const ReactNativeConfig>>();
33+
3134
auto uiManager = std::make_unique<UIManager>();
3235
auto &uiManagerRef = *uiManager;
33-
uiManagerBinding_ =
34-
std::make_shared<UIManagerBinding>(std::move(uiManager));
36+
uiManagerBinding_ = std::make_shared<UIManagerBinding>(std::move(uiManager));
3537

3638
auto eventPipe = [uiManagerBinding = uiManagerBinding_.get()](
3739
jsi::Runtime &runtime,
@@ -93,7 +95,8 @@ void Scheduler::renderTemplateToSurface(
9395
surfaceId,
9496
folly::dynamic::object(),
9597
*componentDescriptorRegistry_,
96-
nMR);
98+
nMR,
99+
reactNativeConfig_);
97100

98101
shadowTreeRegistry_.visit(surfaceId, [=](const ShadowTree &shadowTree) {
99102
shadowTree.complete(

ReactCommon/fabric/uimanager/Scheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <mutex>
1010

11+
#include <react/config/ReactNativeConfig.h>
1112
#include <react/core/ComponentDescriptor.h>
1213
#include <react/core/LayoutConstraints.h>
1314
#include <react/uimanager/ComponentDescriptorRegistry.h>
@@ -94,6 +95,7 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
9495
SharedContextContainer contextContainer_;
9596
RuntimeExecutor runtimeExecutor_;
9697
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
98+
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
9799
};
98100

99101
} // namespace react

ReactCommon/fabric/uimanager/UITemplateProcessor.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
3838
std::vector<SharedShadowNode> &nodes,
3939
std::vector<folly::dynamic> &registers,
4040
const ComponentDescriptorRegistry &componentDescriptorRegistry,
41-
const NativeModuleRegistry &nativeModuleRegistry) {
41+
const NativeModuleRegistry &nativeModuleRegistry,
42+
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig) {
4243
const std::string &opcode = command[0].asString();
4344
const int tagOffset = 420000;
4445
// TODO: change to integer codes and a switch statement
@@ -61,9 +62,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
6162
return nodes[command[1].asInt()];
6263
} else if (opcode == "loadNativeBool") {
6364
int registerNumber = command[1].asInt();
64-
const folly::dynamic &value = nativeModuleRegistry.call(
65-
command[2].asString(), command[3].asString(), command[4]);
66-
registers[registerNumber] = value.asBool();
65+
std::string param = command[4][0].asString();
66+
registers[registerNumber] = reactNativeConfig->getBool(param);
6767
} else if (opcode == "conditional") {
6868
int registerNumber = command[1].asInt();
6969
auto conditionDynamic = registers[registerNumber];
@@ -89,7 +89,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
8989
nodes,
9090
registers,
9191
componentDescriptorRegistry,
92-
nativeModuleRegistry);
92+
nativeModuleRegistry,
93+
reactNativeConfig);
9394
}
9495
} else {
9596
throw std::runtime_error("Unsupported opcode: " + command[0].asString());
@@ -102,7 +103,8 @@ SharedShadowNode UITemplateProcessor::buildShadowTree(
102103
Tag rootTag,
103104
const folly::dynamic &params,
104105
const ComponentDescriptorRegistry &componentDescriptorRegistry,
105-
const NativeModuleRegistry &nativeModuleRegistry) {
106+
const NativeModuleRegistry &nativeModuleRegistry,
107+
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig) {
106108
LOG(INFO)
107109
<< "(strt) UITemplateProcessor inject hardcoded 'server rendered' view tree";
108110

@@ -129,7 +131,8 @@ SharedShadowNode UITemplateProcessor::buildShadowTree(
129131
nodes,
130132
registers,
131133
componentDescriptorRegistry,
132-
nativeModuleRegistry);
134+
nativeModuleRegistry,
135+
reactNativeConfig);
133136
if (ret != nullptr) {
134137
return ret;
135138
}

ReactCommon/fabric/uimanager/UITemplateProcessor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <folly/dynamic.h>
1313

14+
#include <react/config/ReactNativeConfig.h>
1415
#include <react/core/ShadowNode.h>
1516
#include <react/uimanager/ComponentDescriptorRegistry.h>
1617
#include <react/uimanager/UIManagerDelegate.h>
@@ -48,7 +49,8 @@ class UITemplateProcessor {
4849
int rootTag,
4950
const folly::dynamic &params,
5051
const ComponentDescriptorRegistry &componentDescriptorRegistry,
51-
const NativeModuleRegistry &nativeModuleRegistry);
52+
const NativeModuleRegistry &nativeModuleRegistry,
53+
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
5254

5355
private:
5456
static SharedShadowNode runCommand(
@@ -57,7 +59,8 @@ class UITemplateProcessor {
5759
std::vector<SharedShadowNode> &nodes,
5860
std::vector<folly::dynamic> &registers,
5961
const ComponentDescriptorRegistry &componentDescriptorRegistry,
60-
const NativeModuleRegistry &nativeModuleRegistry);
62+
const NativeModuleRegistry &nativeModuleRegistry,
63+
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
6164
};
6265
} // namespace react
6366
} // namespace facebook

ReactCommon/fabric/uimanager/tests/UITemplateProcessorTest.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using namespace facebook::react;
2020
#include <react/components/text/RawTextComponentDescriptor.h>
2121
#include <react/components/text/TextComponentDescriptor.h>
2222
#include <react/components/view/ViewComponentDescriptor.h>
23+
#include <react/config/ReactNativeConfig.h>
2324
#include <react/uimanager/ComponentDescriptorRegistry.h>
2425

2526
namespace facebook {
@@ -63,6 +64,29 @@ NativeModuleRegistry buildNativeModuleRegistry() {
6364
return nMR;
6465
}
6566

67+
class MockReactNativeConfig : public ReactNativeConfig {
68+
public:
69+
MockReactNativeConfig() {}
70+
bool getBool(const std::string &param) const override {
71+
return mockSimpleTestValue_;
72+
}
73+
74+
std::string getString(const std::string &param) const override {
75+
return "";
76+
}
77+
78+
int64_t getInt64(const std::string &param) const override {
79+
return 0;
80+
}
81+
82+
double getDouble(const std::string &param) const override {
83+
return 0.0;
84+
}
85+
};
86+
87+
std::shared_ptr<const ReactNativeConfig> mockReactNativeConfig_ =
88+
std::make_shared<const MockReactNativeConfig>();
89+
6690
} // namespace react
6791
} // namespace facebook
6892

@@ -85,7 +109,8 @@ TEST(UITemplateProcessorTest, testSimpleBytecode) {
85109
surfaceId,
86110
folly::dynamic::object(),
87111
*componentDescriptorRegistry,
88-
nativeModuleRegistry);
112+
nativeModuleRegistry,
113+
mockReactNativeConfig_);
89114
LOG(INFO) << std::endl << root1->getDebugDescription();
90115
auto props1 = std::dynamic_pointer_cast<const ViewProps>(root1->getProps());
91116
ASSERT_NEAR(props1->opacity, 0.5, 0.001);
@@ -120,7 +145,8 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) {
120145
surfaceId,
121146
folly::dynamic::object(),
122147
*componentDescriptorRegistry,
123-
nativeModuleRegistry);
148+
nativeModuleRegistry,
149+
mockReactNativeConfig_);
124150
LOG(INFO) << std::endl << root1->getDebugDescription();
125151
auto props1 = std::dynamic_pointer_cast<const ViewProps>(root1->getProps());
126152
ASSERT_STREQ(props1->testId.c_str(), "root");
@@ -137,7 +163,8 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) {
137163
surfaceId,
138164
folly::dynamic::object(),
139165
*componentDescriptorRegistry,
140-
nativeModuleRegistry);
166+
nativeModuleRegistry,
167+
mockReactNativeConfig_);
141168
auto child_props2 = std::dynamic_pointer_cast<const ViewProps>(
142169
root2->getChildren().at(0)->getProps());
143170
ASSERT_STREQ(child_props2->testId.c_str(), "cond_false");

0 commit comments

Comments
 (0)