Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getInspectorDataForInstance #48335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -62,33 +62,6 @@ UIManagerBinding::~UIManagerBinding() {
<< this << ").";
}

jsi::Value UIManagerBinding::getInspectorDataForInstance(
jsi::Runtime& runtime,
const EventEmitter& eventEmitter) const {
auto eventTarget = eventEmitter.eventTarget_;
EventEmitter::DispatchMutex().lock();

if (!runtime.global().hasProperty(runtime, "__fbBatchedBridge") ||
!eventTarget) {
return jsi::Value::undefined();
}

eventTarget->retain(runtime);
auto instanceHandle = eventTarget->getInstanceHandle(runtime);
eventTarget->release(runtime);
EventEmitter::DispatchMutex().unlock();

if (instanceHandle.isUndefined()) {
return jsi::Value::undefined();
}

return callMethodOfModule(
runtime,
"ReactFabric",
"getInspectorDataForInstance",
{std::move(instanceHandle)});
}

void UIManagerBinding::dispatchEvent(
jsi::Runtime& runtime,
const EventTarget* eventTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class UIManagerBinding : public jsi::HostObject {

~UIManagerBinding() override;

jsi::Value getInspectorDataForInstance(
jsi::Runtime& runtime,
const EventEmitter& eventEmitter) const;

/*
* Delivers raw event data to JavaScript.
* Thread synchronization must be enforced externally.
Expand Down
Loading