From 680dd36fd1507ff7240f677b968bde9d0da6c920 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 12 Apr 2021 00:03:16 -0700 Subject: [PATCH] Introduce new Fabric API setSurfaceProps Summary: This diff introduces a new fabric API called setSurfaceProps that will be used to call the new JS api "setSurfaceProps" changelog: [internal] internal Reviewed By: sammy-SC Differential Revision: D27607588 fbshipit-source-id: 36a19f728af244d7e72687d9305b1c568e2b8ec6 --- .../react/renderer/uimanager/UIManager.cpp | 16 ++++++++++ .../react/renderer/uimanager/UIManager.h | 5 ++++ .../renderer/uimanager/UIManagerBinding.cpp | 30 +++++++++++++++++++ .../renderer/uimanager/UIManagerBinding.h | 11 +++++++ 4 files changed, 62 insertions(+) diff --git a/ReactCommon/react/renderer/uimanager/UIManager.cpp b/ReactCommon/react/renderer/uimanager/UIManager.cpp index dec25e99fd1..9824c475652 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -164,6 +164,22 @@ void UIManager::startSurface( }); } +void UIManager::setSurfaceProps( + SurfaceId surfaceId, + std::string const &moduleName, + folly::dynamic const &props) const { + SystraceSection s("UIManager::setSurfaceProps"); + + runtimeExecutor_([=](jsi::Runtime &runtime) { + auto uiManagerBinding = UIManagerBinding::getBinding(runtime); + if (!uiManagerBinding) { + return; + } + + uiManagerBinding->setSurfaceProps(runtime, surfaceId, moduleName, props); + }); +} + ShadowTree::Unique UIManager::stopSurface(SurfaceId surfaceId) const { SystraceSection s("UIManager::stopSurface"); diff --git a/ReactCommon/react/renderer/uimanager/UIManager.h b/ReactCommon/react/renderer/uimanager/UIManager.h index bfb73da9cb0..17a608196dd 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.h +++ b/ReactCommon/react/renderer/uimanager/UIManager.h @@ -89,6 +89,11 @@ class UIManager final : public ShadowTreeDelegate { std::string const &moduleName, folly::dynamic const &props) const; + void setSurfaceProps( + SurfaceId surfaceId, + std::string const &moduleName, + folly::dynamic const &props) const; + ShadowTree::Unique stopSurface(SurfaceId surfaceId) const; #pragma mark - ShadowTreeDelegate diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index 65d5eb60ac9..a281b9cacbc 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -169,6 +169,36 @@ void UIManagerBinding::startSurface( } } +void UIManagerBinding::setSurfaceProps( + jsi::Runtime &runtime, + SurfaceId surfaceId, + std::string const &moduleName, + folly::dynamic const &initalProps) const { + folly::dynamic parameters = folly::dynamic::object(); + parameters["rootTag"] = surfaceId; + parameters["initialProps"] = initalProps; + parameters["fabric"] = true; + + if (moduleName.compare("LogBox") != 0 && + runtime.global().hasProperty(runtime, "RN$SurfaceRegistry")) { + auto registry = + runtime.global().getPropertyAsObject(runtime, "RN$SurfaceRegistry"); + auto method = registry.getPropertyAsFunction(runtime, "setSurfaceProps"); + + method.call( + runtime, + {jsi::String::createFromUtf8(runtime, moduleName), + jsi::valueFromDynamic(runtime, parameters)}); + } else { + callMethodOfModule( + runtime, + "AppRegistry", + "setSurfaceProps", + {jsi::String::createFromUtf8(runtime, moduleName), + jsi::valueFromDynamic(runtime, parameters)}); + } +} + void UIManagerBinding::stopSurface(jsi::Runtime &runtime, SurfaceId surfaceId) const { auto global = runtime.global(); diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.h b/ReactCommon/react/renderer/uimanager/UIManagerBinding.h index 8c68cdeda5b..5880ebe4e9c 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.h +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.h @@ -55,6 +55,17 @@ class UIManagerBinding : public jsi::HostObject { std::string const &moduleName, folly::dynamic const &initalProps) const; + /* + * Updates the React Native Surface identified with surfaceId and moduleName + * with the given props. + * Thread synchronization must be enforced externally. + */ + void setSurfaceProps( + jsi::Runtime &runtime, + SurfaceId surfaceId, + std::string const &moduleName, + folly::dynamic const &props) const; + /* * Stops React Native Surface with given id. * Thread synchronization must be enforced externally.