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
This commit is contained in:
parent
3b6f229eb9
commit
4f9a3bc8f6
|
@ -58,6 +58,7 @@ rn_xplat_cxx_library(
|
|||
"xplat//jsi:JSIDynamic",
|
||||
"xplat//jsi:jsi",
|
||||
"xplat//third-party/glog:glog",
|
||||
react_native_xplat_target("config:config"),
|
||||
react_native_xplat_target("fabric/components/root:root"),
|
||||
react_native_xplat_target("fabric/components/view:view"),
|
||||
react_native_xplat_target("fabric/mounting:mounting"),
|
||||
|
@ -83,6 +84,7 @@ fb_xplat_cxx_test(
|
|||
"xplat//folly:molly",
|
||||
"xplat//third-party/gmock:gtest",
|
||||
":uimanager",
|
||||
react_native_xplat_target("config:config"),
|
||||
react_native_xplat_target("fabric/components/activityindicator:activityindicator"),
|
||||
react_native_xplat_target("fabric/components/image:image"),
|
||||
react_native_xplat_target("fabric/components/root:root"),
|
||||
|
|
|
@ -28,10 +28,12 @@ Scheduler::Scheduler(const SharedContextContainer &contextContainer)
|
|||
runtimeExecutor_ =
|
||||
contextContainer->getInstance<RuntimeExecutor>("runtime-executor");
|
||||
|
||||
reactNativeConfig_ =
|
||||
contextContainer->getInstance<std::shared_ptr<const ReactNativeConfig>>();
|
||||
|
||||
auto uiManager = std::make_unique<UIManager>();
|
||||
auto &uiManagerRef = *uiManager;
|
||||
uiManagerBinding_ =
|
||||
std::make_shared<UIManagerBinding>(std::move(uiManager));
|
||||
uiManagerBinding_ = std::make_shared<UIManagerBinding>(std::move(uiManager));
|
||||
|
||||
auto eventPipe = [uiManagerBinding = uiManagerBinding_.get()](
|
||||
jsi::Runtime &runtime,
|
||||
|
@ -93,7 +95,8 @@ void Scheduler::renderTemplateToSurface(
|
|||
surfaceId,
|
||||
folly::dynamic::object(),
|
||||
*componentDescriptorRegistry_,
|
||||
nMR);
|
||||
nMR,
|
||||
reactNativeConfig_);
|
||||
|
||||
shadowTreeRegistry_.visit(surfaceId, [=](const ShadowTree &shadowTree) {
|
||||
shadowTree.complete(
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/core/ComponentDescriptor.h>
|
||||
#include <react/core/LayoutConstraints.h>
|
||||
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
||||
|
@ -94,6 +95,7 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
|||
SharedContextContainer contextContainer_;
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
|
||||
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -38,7 +38,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
|
|||
std::vector<SharedShadowNode> &nodes,
|
||||
std::vector<folly::dynamic> ®isters,
|
||||
const ComponentDescriptorRegistry &componentDescriptorRegistry,
|
||||
const NativeModuleRegistry &nativeModuleRegistry) {
|
||||
const NativeModuleRegistry &nativeModuleRegistry,
|
||||
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig) {
|
||||
const std::string &opcode = command[0].asString();
|
||||
const int tagOffset = 420000;
|
||||
// TODO: change to integer codes and a switch statement
|
||||
|
@ -61,9 +62,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
|
|||
return nodes[command[1].asInt()];
|
||||
} else if (opcode == "loadNativeBool") {
|
||||
int registerNumber = command[1].asInt();
|
||||
const folly::dynamic &value = nativeModuleRegistry.call(
|
||||
command[2].asString(), command[3].asString(), command[4]);
|
||||
registers[registerNumber] = value.asBool();
|
||||
std::string param = command[4][0].asString();
|
||||
registers[registerNumber] = reactNativeConfig->getBool(param);
|
||||
} else if (opcode == "conditional") {
|
||||
int registerNumber = command[1].asInt();
|
||||
auto conditionDynamic = registers[registerNumber];
|
||||
|
@ -89,7 +89,8 @@ SharedShadowNode UITemplateProcessor::runCommand(
|
|||
nodes,
|
||||
registers,
|
||||
componentDescriptorRegistry,
|
||||
nativeModuleRegistry);
|
||||
nativeModuleRegistry,
|
||||
reactNativeConfig);
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("Unsupported opcode: " + command[0].asString());
|
||||
|
@ -102,7 +103,8 @@ SharedShadowNode UITemplateProcessor::buildShadowTree(
|
|||
Tag rootTag,
|
||||
const folly::dynamic ¶ms,
|
||||
const ComponentDescriptorRegistry &componentDescriptorRegistry,
|
||||
const NativeModuleRegistry &nativeModuleRegistry) {
|
||||
const NativeModuleRegistry &nativeModuleRegistry,
|
||||
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig) {
|
||||
LOG(INFO)
|
||||
<< "(strt) UITemplateProcessor inject hardcoded 'server rendered' view tree";
|
||||
|
||||
|
@ -129,7 +131,8 @@ SharedShadowNode UITemplateProcessor::buildShadowTree(
|
|||
nodes,
|
||||
registers,
|
||||
componentDescriptorRegistry,
|
||||
nativeModuleRegistry);
|
||||
nativeModuleRegistry,
|
||||
reactNativeConfig);
|
||||
if (ret != nullptr) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/core/ShadowNode.h>
|
||||
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
||||
#include <react/uimanager/UIManagerDelegate.h>
|
||||
|
@ -48,7 +49,8 @@ class UITemplateProcessor {
|
|||
int rootTag,
|
||||
const folly::dynamic ¶ms,
|
||||
const ComponentDescriptorRegistry &componentDescriptorRegistry,
|
||||
const NativeModuleRegistry &nativeModuleRegistry);
|
||||
const NativeModuleRegistry &nativeModuleRegistry,
|
||||
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
|
||||
|
||||
private:
|
||||
static SharedShadowNode runCommand(
|
||||
|
@ -57,7 +59,8 @@ class UITemplateProcessor {
|
|||
std::vector<SharedShadowNode> &nodes,
|
||||
std::vector<folly::dynamic> ®isters,
|
||||
const ComponentDescriptorRegistry &componentDescriptorRegistry,
|
||||
const NativeModuleRegistry &nativeModuleRegistry);
|
||||
const NativeModuleRegistry &nativeModuleRegistry,
|
||||
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
|
||||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
|
|
@ -20,6 +20,7 @@ using namespace facebook::react;
|
|||
#include <react/components/text/RawTextComponentDescriptor.h>
|
||||
#include <react/components/text/TextComponentDescriptor.h>
|
||||
#include <react/components/view/ViewComponentDescriptor.h>
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
||||
|
||||
namespace facebook {
|
||||
|
@ -63,6 +64,29 @@ NativeModuleRegistry buildNativeModuleRegistry() {
|
|||
return nMR;
|
||||
}
|
||||
|
||||
class MockReactNativeConfig : public ReactNativeConfig {
|
||||
public:
|
||||
MockReactNativeConfig() {}
|
||||
bool getBool(const std::string ¶m) const override {
|
||||
return mockSimpleTestValue_;
|
||||
}
|
||||
|
||||
std::string getString(const std::string ¶m) const override {
|
||||
return "";
|
||||
}
|
||||
|
||||
int64_t getInt64(const std::string ¶m) const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double getDouble(const std::string ¶m) const override {
|
||||
return 0.0;
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<const ReactNativeConfig> mockReactNativeConfig_ =
|
||||
std::make_shared<const MockReactNativeConfig>();
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
|
@ -85,7 +109,8 @@ TEST(UITemplateProcessorTest, testSimpleBytecode) {
|
|||
surfaceId,
|
||||
folly::dynamic::object(),
|
||||
*componentDescriptorRegistry,
|
||||
nativeModuleRegistry);
|
||||
nativeModuleRegistry,
|
||||
mockReactNativeConfig_);
|
||||
LOG(INFO) << std::endl << root1->getDebugDescription();
|
||||
auto props1 = std::dynamic_pointer_cast<const ViewProps>(root1->getProps());
|
||||
ASSERT_NEAR(props1->opacity, 0.5, 0.001);
|
||||
|
@ -120,7 +145,8 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) {
|
|||
surfaceId,
|
||||
folly::dynamic::object(),
|
||||
*componentDescriptorRegistry,
|
||||
nativeModuleRegistry);
|
||||
nativeModuleRegistry,
|
||||
mockReactNativeConfig_);
|
||||
LOG(INFO) << std::endl << root1->getDebugDescription();
|
||||
auto props1 = std::dynamic_pointer_cast<const ViewProps>(root1->getProps());
|
||||
ASSERT_STREQ(props1->testId.c_str(), "root");
|
||||
|
@ -137,7 +163,8 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) {
|
|||
surfaceId,
|
||||
folly::dynamic::object(),
|
||||
*componentDescriptorRegistry,
|
||||
nativeModuleRegistry);
|
||||
nativeModuleRegistry,
|
||||
mockReactNativeConfig_);
|
||||
auto child_props2 = std::dynamic_pointer_cast<const ViewProps>(
|
||||
root2->getChildren().at(0)->getProps());
|
||||
ASSERT_STREQ(child_props2->testId.c_str(), "cond_false");
|
||||
|
|
Loading…
Reference in New Issue