Skip to content

Commit

Permalink
Rename SurfaceRegistryBinding to AppRegistryBinding (facebook#48337)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48337

`SurfaceRegistryBinding` refers to a forked `SurfaceRegistry` we had for a while in bridgeless but which was merged back into `AppRegistry`. Align the native name as well to make it explicit that all this class does is call into `AppRegistry`.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D67342499
  • Loading branch information
javache authored and facebook-github-bot committed Jan 7, 2025
1 parent 2b6213a commit f603349
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/

#include "SurfaceRegistryBinding.h"
#include "AppRegistryBinding.h"
#include <cxxreact/TraceSection.h>
#include <react/renderer/uimanager/primitives.h>

namespace facebook::react {

void SurfaceRegistryBinding::startSurface(
void AppRegistryBinding::startSurface(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode) {
TraceSection s("SurfaceRegistryBinding::startSurface");
TraceSection s("AppRegistryBinding::startSurface");
jsi::Object parameters(runtime);
parameters.setProperty(runtime, "rootTag", surfaceId);
parameters.setProperty(
Expand All @@ -28,7 +28,7 @@ void SurfaceRegistryBinding::startSurface(
auto registry = global.getProperty(runtime, "RN$AppRegistry");
if (!registry.isObject()) {
throw std::runtime_error(
"SurfaceRegistryBinding::startSurface failed. Global was not installed.");
"AppRegistryBinding::startSurface failed. Global was not installed.");
}
auto method = std::move(registry).asObject(runtime).getPropertyAsFunction(
runtime, "runApplication");
Expand All @@ -39,7 +39,7 @@ void SurfaceRegistryBinding::startSurface(
jsi::Value(runtime, displayModeToInt(displayMode))});
}

void SurfaceRegistryBinding::setSurfaceProps(
void AppRegistryBinding::setSurfaceProps(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
Expand All @@ -56,7 +56,7 @@ void SurfaceRegistryBinding::setSurfaceProps(
auto registry = global.getProperty(runtime, "RN$AppRegistry");
if (!registry.isObject()) {
throw std::runtime_error(
"SurfaceRegistryBinding::setSurfaceProps failed. Global was not installed.");
"AppRegistryBinding::setSurfaceProps failed. Global was not installed.");
}

auto method = std::move(registry).asObject(runtime).getPropertyAsFunction(
Expand All @@ -68,15 +68,15 @@ void SurfaceRegistryBinding::setSurfaceProps(
jsi::Value(runtime, displayModeToInt(displayMode))});
}

void SurfaceRegistryBinding::stopSurface(
void AppRegistryBinding::stopSurface(
jsi::Runtime& runtime,
SurfaceId surfaceId) {
auto global = runtime.global();
auto stopFunction = global.getProperty(runtime, "RN$stopSurface");
if (!stopFunction.isObject() ||
!stopFunction.asObject(runtime).isFunction(runtime)) {
throw std::runtime_error(
"SurfaceRegistryBinding::stopSurface failed. Global was not installed.");
"AppRegistryBinding::stopSurface failed. Global was not installed.");
}

std::move(stopFunction)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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 <folly/dynamic.h>
#include <jsi/jsi.h>
#include <react/renderer/core/ReactPrimitives.h>

namespace facebook::react {

class AppRegistryBinding final {
public:
AppRegistryBinding() = delete;

/*
* Starts React Native Surface with given id, moduleName, and props.
* Thread synchronization must be enforced externally.
*/
static void startSurface(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode);

/*
* Updates the React Native Surface identified with surfaceId and moduleName
* with the given props.
* Thread synchronization must be enforced externally.
*/
static void setSurfaceProps(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode);

/*
* Stops React Native Surface with given id.
* Thread synchronization must be enforced externally.
*/
static void stopSurface(jsi::Runtime& runtime, SurfaceId surfaceId);
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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 <folly/dynamic.h>
#include <jsi/jsi.h>
#include <react/renderer/core/ReactPrimitives.h>

namespace facebook::react {

class SurfaceRegistryBinding final {
public:
SurfaceRegistryBinding() = delete;

/*
* Starts React Native Surface with given id, moduleName, and props.
* Thread synchronization must be enforced externally.
*/
static void startSurface(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode);

/*
* Updates the React Native Surface identified with surfaceId and moduleName
* with the given props.
* Thread synchronization must be enforced externally.
*/
static void setSurfaceProps(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode);

/*
* Stops React Native Surface with given id.
* Thread synchronization must be enforced externally.
*/
static void stopSurface(jsi::Runtime& runtime, SurfaceId surfaceId);
};
#warning \
"The SurfaceRegistryBinding.h header has been renamed to AppRegistryBinding.h"

} // namespace facebook::react
#include <react/renderer/uimanager/AppRegistryBinding.h>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <react/renderer/core/DynamicPropsUtilities.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ShadowNodeFragment.h>
#include <react/renderer/uimanager/SurfaceRegistryBinding.h>
#include <react/renderer/uimanager/AppRegistryBinding.h>
#include <react/renderer/uimanager/UIManagerBinding.h>
#include <react/renderer/uimanager/UIManagerCommitHook.h>
#include <react/renderer/uimanager/UIManagerMountHook.h>
Expand Down Expand Up @@ -237,7 +237,7 @@ void UIManager::startSurface(

runtimeExecutor_([=](jsi::Runtime& runtime) {
TraceSection s("UIManager::startSurface::onRuntime");
SurfaceRegistryBinding::startSurface(
AppRegistryBinding::startSurface(
runtime, surfaceId, moduleName, props, displayMode);
});
}
Expand All @@ -255,7 +255,7 @@ void UIManager::setSurfaceProps(
TraceSection s("UIManager::setSurfaceProps");

runtimeExecutor_([=](jsi::Runtime& runtime) {
SurfaceRegistryBinding::setSurfaceProps(
AppRegistryBinding::setSurfaceProps(
runtime, surfaceId, moduleName, props, displayMode);
});
}
Expand All @@ -275,7 +275,7 @@ ShadowTree::Unique UIManager::stopSurface(SurfaceId surfaceId) const {
// commits from the JavaScript side will not be able to reference a
// `ShadowTree` and will fail silently.
runtimeExecutor_([=](jsi::Runtime& runtime) {
SurfaceRegistryBinding::stopSurface(runtime, surfaceId);
AppRegistryBinding::stopSurface(runtime, surfaceId);
});

if (leakChecker_) {
Expand Down

0 comments on commit f603349

Please sign in to comment.