Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,6 @@ public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/brid
public fun dispatchCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
public fun getColor (I[Ljava/lang/String;)I
public fun getEventDispatcher ()Lcom/facebook/react/uimanager/events/EventDispatcher;
public fun getInspectorDataForInstance (ILandroid/view/View;)Lcom/facebook/react/bridge/ReadableMap;
public fun getPerformanceCounters ()Ljava/util/Map;
public fun getThemeData (I[F)Z
public fun initialize ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,6 @@ public <T extends View> int addRootView(final T rootView, final WritableMap init
return rootTag;
}

/**
* This API returns metadata associated to the React Component that rendered the Android View
* received as a parameter.
*
* @param surfaceId {@link int} that represents the surfaceId for the View received as a
* parameter. In practice surfaceId can be retrieved calling the {@link View#getId()} method
* on the {@link ReactRoot} that holds the View received as a second parameter.
* @param view {@link View} view that will be used to retrieve the React view hierarchy metadata.
* @return a {@link ReadableMap} that contains metadata associated to the React Component that
* rendered the Android View received as a parameter. For more details about the keys stored
* in the {@link ReadableMap} refer to the "getInspectorDataForInstance" method from
* jni/react/fabric/Binding.cpp file.
*/
@UiThread
@ThreadConfined(UI)
public ReadableMap getInspectorDataForInstance(final int surfaceId, final View view) {
UiThreadUtil.assertOnUiThread();
int reactTag = view.getId();

EventEmitterWrapper eventEmitter = mMountingManager.getEventEmitter(surfaceId, reactTag);
return mBinding.getInspectorDataForInstance(eventEmitter);
}

@Override
@AnyThread
@ThreadConfined(ANY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import android.annotation.SuppressLint
import com.facebook.jni.HybridClassBase
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.ReadableNativeMap
import com.facebook.react.bridge.RuntimeExecutor
import com.facebook.react.bridge.RuntimeScheduler
import com.facebook.react.common.mapbuffer.MapBufferSoLoader
import com.facebook.react.fabric.events.EventBeatManager
import com.facebook.react.fabric.events.EventEmitterWrapper
import com.facebook.react.uimanager.PixelUtil.getDisplayMetricDensity

@DoNotStrip
Expand Down Expand Up @@ -82,10 +80,6 @@ internal class FabricUIManagerBinding : HybridClassBase() {

public external fun reportMount(surfaceId: Int)

public external fun getInspectorDataForInstance(
eventEmitterWrapper: EventEmitterWrapper?
): ReadableNativeMap?

public fun register(
runtimeExecutor: RuntimeExecutor,
runtimeScheduler: RuntimeScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,6 @@ std::shared_ptr<Scheduler> FabricUIManagerBinding::getScheduler() {
return scheduler_;
}

jni::local_ref<ReadableNativeMap::jhybridobject>
FabricUIManagerBinding::getInspectorDataForInstance(
jni::alias_ref<EventEmitterWrapper::javaobject> eventEmitterWrapper) {
auto scheduler = getScheduler();
if (!scheduler) {
LOG(ERROR) << "FabricUIManagerBinding::startSurface: scheduler disappeared";
return ReadableNativeMap::newObjectCxxArgs(folly::dynamic::object());
}

EventEmitterWrapper* cEventEmitter = cthis(eventEmitterWrapper);
InspectorData data =
scheduler->getInspectorDataForInstance(*cEventEmitter->eventEmitter);

folly::dynamic result = folly::dynamic::object;
result["fileName"] = data.fileName;
result["lineNumber"] = data.lineNumber;
result["columnNumber"] = data.columnNumber;
result["selectedIndex"] = data.selectedIndex;
result["props"] = data.props;
auto hierarchy = folly::dynamic::array();
for (const auto& hierarchyItem : data.hierarchy) {
hierarchy.push_back(hierarchyItem);
}
result["hierarchy"] = hierarchy;
return ReadableNativeMap::newObjectCxxArgs(result);
}

void FabricUIManagerBinding::setPixelDensity(float pointScaleFactor) {
pointScaleFactor_ = pointScaleFactor;
}
Expand Down Expand Up @@ -661,9 +634,6 @@ void FabricUIManagerBinding::registerNatives() {
"installFabricUIManager",
FabricUIManagerBinding::installFabricUIManager),
makeNativeMethod("startSurface", FabricUIManagerBinding::startSurface),
makeNativeMethod(
"getInspectorDataForInstance",
FabricUIManagerBinding::getInspectorDataForInstance),
makeNativeMethod(
"startSurfaceWithConstraints",
FabricUIManagerBinding::startSurfaceWithConstraints),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
jboolean isRTL,
jboolean doLeftAndRightSwapInRTL);

jni::local_ref<ReadableNativeMap::jhybridobject> getInspectorDataForInstance(
jni::alias_ref<EventEmitterWrapper::javaobject> eventEmitterWrapper);

static void initHybrid(jni::alias_ref<jhybridobject> jobj);

void installFabricUIManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,6 @@ void Scheduler::registerSurface(
surfaceHandler.setUIManager(uiManager_.get());
}

InspectorData Scheduler::getInspectorDataForInstance(
const EventEmitter& eventEmitter) const noexcept {
return executeSynchronouslyOnSameThread_CAN_DEADLOCK<InspectorData>(
runtimeExecutor_, [=](jsi::Runtime& runtime) -> InspectorData {
auto uiManagerBinding = UIManagerBinding::getBinding(runtime);
auto value = uiManagerBinding->getInspectorDataForInstance(
runtime, eventEmitter);

// TODO T97216348: avoid transforming jsi into folly::dynamic
auto dynamic = jsi::dynamicFromValue(runtime, value);
auto source = dynamic["source"];

InspectorData result = {};
result.fileName =
source["fileName"].isNull() ? "" : source["fileName"].c_str();
result.lineNumber = (int)source["lineNumber"].getDouble();
result.columnNumber = (int)source["columnNumber"].getDouble();
result.selectedIndex = (int)dynamic["selectedIndex"].getDouble();
// TODO T97216348: remove folly::dynamic from InspectorData struct
result.props = dynamic["props"];
auto hierarchy = dynamic["hierarchy"];
for (auto& i : hierarchy) {
auto viewHierarchyValue = i["name"];
if (!viewHierarchyValue.isNull()) {
result.hierarchy.emplace_back(viewHierarchyValue.c_str());
}
}
return result;
});
}

void Scheduler::unregisterSurface(
const SurfaceHandler& surfaceHandler) const noexcept {
surfaceHandler.setUIManager(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class Scheduler final : public UIManagerDelegate {
void registerSurface(const SurfaceHandler& surfaceHandler) const noexcept;
void unregisterSurface(const SurfaceHandler& surfaceHandler) const noexcept;

InspectorData getInspectorDataForInstance(
const EventEmitter& eventEmitter) const noexcept;

/*
* This is broken. Please do not use.
* `ComponentDescriptor`s are not designed to be used outside of `UIManager`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.
*/

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

namespace facebook::react {

/* static */ void AppRegistryBinding::startSurface(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode) {
TraceSection s("AppRegistryBinding::startSurface");
jsi::Object parameters(runtime);
parameters.setProperty(runtime, "rootTag", surfaceId);
parameters.setProperty(
runtime, "initialProps", jsi::valueFromDynamic(runtime, initialProps));
parameters.setProperty(runtime, "fabric", true);

auto global = runtime.global();
auto registry = global.getProperty(runtime, "RN$AppRegistry");
if (!registry.isObject()) {
throw std::runtime_error(
"AppRegistryBinding::startSurface failed. Global was not installed.");
}
auto method = std::move(registry).asObject(runtime).getPropertyAsFunction(
runtime, "runApplication");
method.call(
runtime,
{jsi::String::createFromUtf8(runtime, moduleName),
std::move(parameters),
jsi::Value(runtime, displayModeToInt(displayMode))});
}

/* static */ void AppRegistryBinding::setSurfaceProps(
jsi::Runtime& runtime,
SurfaceId surfaceId,
const std::string& moduleName,
const folly::dynamic& initialProps,
DisplayMode displayMode) {
TraceSection s("UIManagerBinding::setSurfaceProps");
jsi::Object parameters(runtime);
parameters.setProperty(runtime, "rootTag", surfaceId);
parameters.setProperty(
runtime, "initialProps", jsi::valueFromDynamic(runtime, initialProps));
parameters.setProperty(runtime, "fabric", true);

auto global = runtime.global();
auto registry = global.getProperty(runtime, "RN$AppRegistry");
if (!registry.isObject()) {
throw std::runtime_error(
"AppRegistryBinding::setSurfaceProps failed. Global was not installed.");
}

auto method = std::move(registry).asObject(runtime).getPropertyAsFunction(
runtime, "setSurfaceProps");
method.call(
runtime,
{jsi::String::createFromUtf8(runtime, moduleName),
std::move(parameters),
jsi::Value(runtime, displayModeToInt(displayMode))});
}

/* static */ 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(
"AppRegistryBinding::stopSurface failed. Global was not installed.");
}

std::move(stopFunction)
.asObject(runtime)
.asFunction(runtime)
.call(runtime, {jsi::Value{surfaceId}});
}

} // namespace facebook::react
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
Loading
Loading