Skip to content

Commit 49002fa

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Expose ShadowNodeFamily to RawEvent (facebook#51267)
Summary: Pull Request resolved: facebook#51267 Changelog: [Internal] This diff exposes the corresponding target ShadowNodeFamily to a RawEvent through a weak pointer. This is necessary for the upcoming move of pointer event interception from the JS to main thread. Reviewed By: javache Differential Revision: D74500630 fbshipit-source-id: 3bcf32855a004e091be64b6171dc65127375534c
1 parent 4fda28e commit 49002fa

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
171171
std::make_shared<EventTarget>(
172172
fragment.instanceHandle, fragment.surfaceId),
173173
eventDispatcher_);
174-
return std::make_shared<ShadowNodeFamily>(
175-
fragment, std::move(eventEmitter), eventDispatcher_, *this);
174+
auto family = std::make_shared<ShadowNodeFamily>(
175+
fragment, eventEmitter, eventDispatcher_, *this);
176+
eventEmitter->setShadowNodeFamily(family);
177+
return family;
176178
}
177179

178180
protected:

packages/react-native/ReactCommon/react/renderer/core/EventEmitter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void EventEmitter::dispatchEvent(
9898
normalizeEventType(std::move(type)),
9999
std::move(payload),
100100
eventTarget_,
101+
shadowNodeFamily_,
101102
category));
102103
}
103104

@@ -123,6 +124,7 @@ void EventEmitter::dispatchUniqueEvent(
123124
normalizeEventType(std::move(type)),
124125
std::move(payload),
125126
eventTarget_,
127+
shadowNodeFamily_,
126128
RawEvent::Category::Continuous));
127129
}
128130

@@ -149,6 +151,11 @@ void EventEmitter::setEnabled(bool enabled) const {
149151
}
150152
}
151153

154+
void EventEmitter::setShadowNodeFamily(
155+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily) const {
156+
shadowNodeFamily_ = std::move(shadowNodeFamily);
157+
}
158+
152159
const SharedEventTarget& EventEmitter::getEventTarget() const {
153160
return eventTarget_;
154161
}

packages/react-native/ReactCommon/react/renderer/core/EventEmitter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class EventEmitter {
5757
*/
5858
void setEnabled(bool enabled) const;
5959

60+
/*
61+
* Sets a weak reference to the cooresponding ShadowNodeFamily
62+
*/
63+
void setShadowNodeFamily(
64+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily) const;
65+
6066
const SharedEventTarget& getEventTarget() const;
6167

6268
/*
@@ -106,6 +112,7 @@ class EventEmitter {
106112
friend class UIManagerBinding;
107113

108114
mutable SharedEventTarget eventTarget_;
115+
mutable std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily_;
109116

110117
EventDispatcher::Weak eventDispatcher_;
111118
mutable int enableCounter_{0};

packages/react-native/ReactCommon/react/renderer/core/RawEvent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ RawEvent::RawEvent(
1313
std::string type,
1414
SharedEventPayload eventPayload,
1515
SharedEventTarget eventTarget,
16+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily,
1617
Category category,
1718
bool isUnique)
1819
: type(std::move(type)),
1920
eventPayload(std::move(eventPayload)),
2021
eventTarget(std::move(eventTarget)),
22+
shadowNodeFamily(std::move(shadowNodeFamily)),
2123
category(category),
2224
isUnique(isUnique) {}
2325

packages/react-native/ReactCommon/react/renderer/core/RawEvent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace facebook::react {
1919

20+
class ShadowNodeFamily;
21+
2022
/*
2123
* Represents ready-to-dispatch event object.
2224
*/
@@ -69,12 +71,14 @@ struct RawEvent {
6971
std::string type,
7072
SharedEventPayload eventPayload,
7173
SharedEventTarget eventTarget,
74+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily,
7275
Category category = Category::Unspecified,
7376
bool isUnique = false);
7477

7578
std::string type;
7679
SharedEventPayload eventPayload;
7780
SharedEventTarget eventTarget;
81+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily;
7882
Category category;
7983
EventTag loggingTag{0};
8084
bool isUnique{false};

packages/react-native/ReactCommon/react/renderer/core/tests/EventQueueProcessorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <react/renderer/core/EventPipe.h>
1313
#include <react/renderer/core/EventQueueProcessor.h>
1414
#include <react/renderer/core/EventTarget.h>
15+
#include <react/renderer/core/ShadowNodeFamily.h>
1516
#include <react/renderer/core/StatePipe.h>
1617
#include <react/renderer/core/ValueFactoryEventPayload.h>
1718

@@ -68,6 +69,7 @@ TEST_F(EventQueueProcessorTest, singleUnspecifiedEvent) {
6869
"my type",
6970
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
7071
nullptr,
72+
{},
7173
RawEvent::Category::Unspecified)});
7274

7375
EXPECT_EQ(eventPriorities_.size(), 1);
@@ -82,21 +84,25 @@ TEST_F(EventQueueProcessorTest, continuousEvent) {
8284
"touchStart",
8385
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
8486
nullptr,
87+
{},
8588
RawEvent::Category::ContinuousStart),
8689
RawEvent(
8790
"touchMove",
8891
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
8992
nullptr,
93+
{},
9094
RawEvent::Category::Unspecified),
9195
RawEvent(
9296
"touchEnd",
9397
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
9498
nullptr,
99+
{},
95100
RawEvent::Category::ContinuousEnd),
96101
RawEvent(
97102
"custom event",
98103
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
99104
nullptr,
105+
{},
100106
RawEvent::Category::Unspecified)});
101107

102108
EXPECT_EQ(eventPriorities_.size(), 4);
@@ -122,6 +128,7 @@ TEST_F(EventQueueProcessorTest, alwaysContinuousEvent) {
122128
"onScroll",
123129
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
124130
nullptr,
131+
{},
125132
RawEvent::Category::Continuous),
126133
});
127134

@@ -139,6 +146,7 @@ TEST_F(EventQueueProcessorTest, alwaysDiscreteEvent) {
139146
"onChange",
140147
std::make_shared<ValueFactoryEventPayload>(dummyValueFactory_),
141148
nullptr,
149+
{},
142150
RawEvent::Category::Discrete),
143151
});
144152

0 commit comments

Comments
 (0)