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

Add surfaceId to EventTarget #46254

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
ShadowNodeFamily::Shared createFamily(
const ShadowNodeFamilyFragment& fragment) const override {
auto eventEmitter = std::make_shared<const ConcreteEventEmitter>(
std::make_shared<EventTarget>(fragment.instanceHandle),
std::make_shared<EventTarget>(
fragment.instanceHandle, fragment.surfaceId),
eventDispatcher_);
return std::make_shared<ShadowNodeFamily>(
fragment, std::move(eventEmitter), eventDispatcher_, *this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ namespace facebook::react {

using Tag = EventTarget::Tag;

EventTarget::EventTarget(InstanceHandle::Shared instanceHandle)
EventTarget::EventTarget(
InstanceHandle::Shared instanceHandle,
SurfaceId surfaceId)
: instanceHandle_(std::move(instanceHandle)),
surfaceId_(surfaceId),
strongInstanceHandle_(jsi::Value::null()) {}

void EventTarget::setEnabled(bool enabled) const {
Expand Down Expand Up @@ -64,6 +67,10 @@ jsi::Value EventTarget::getInstanceHandle(jsi::Runtime& runtime) const {
return jsi::Value(runtime, strongInstanceHandle_);
}

SurfaceId EventTarget::getSurfaceId() const {
return surfaceId_;
}

Tag EventTarget::getTag() const {
return instanceHandle_->getTag();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class EventTarget {
/*
* Constructs an EventTarget from a weak instance handler and a tag.
*/
explicit EventTarget(InstanceHandle::Shared instanceHandle);
explicit EventTarget(
InstanceHandle::Shared instanceHandle,
SurfaceId surfaceId);

/*
* Sets the `enabled` flag that allows creating a strong instance handle from
Expand All @@ -59,13 +61,16 @@ class EventTarget {
*/
jsi::Value getInstanceHandle(jsi::Runtime& runtime) const;

SurfaceId getSurfaceId() const;

/*
* Deprecated. Do not use.
*/
Tag getTag() const;

private:
const InstanceHandle::Shared instanceHandle_;
const SurfaceId surfaceId_;
mutable bool enabled_{false}; // Protected by `EventEmitter::DispatchMutex()`.
mutable jsi::Value strongInstanceHandle_; // Protected by `jsi::Runtime &`.
mutable size_t retainCount_{0}; // Protected by `jsi::Runtime &`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ TEST(EventTargetTests, getInstanceHandle) {

EXPECT_EQ(instanceHandle->getTag(), 1);

auto eventTarget = EventTarget(std::move(instanceHandle));
auto eventTarget = EventTarget(std::move(instanceHandle), 41);

EXPECT_EQ(eventTarget.getTag(), 1);

EXPECT_EQ(eventTarget.getSurfaceId(), 41);

EXPECT_TRUE(eventTarget.getInstanceHandle(*runtime).isNull());

eventTarget.retain(*runtime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ void RuntimeScheduler_Modern::runEventLoopTick(
performMicrotaskCheckpoint(runtime);
}

if (ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop()) {
// "Update the rendering" step.
updateRendering();
}

if (ReactNativeFeatureFlags::enableLongTaskAPI()) {
auto taskEndTime = now_();
markYieldingOpportunity(taskEndTime);
reportLongTasks(task, taskStartTime, taskEndTime);
}

if (ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop()) {
// "Update the rendering" step.
updateRendering();
}

currentTask_ = nullptr;
}

Expand Down
Loading