Skip to content

Commit 6172988

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Add dispatchEvent API to EventEmitter that accepts an EventPayload directly (and use it for Pointer Events) (facebook#38301)
Summary: Pull Request resolved: facebook#38301 Changelog: [Internal] - Add dispatchEvent API to EventEmitter that accepts an EventPayload directly This diff adds a deeper overload of dispatchEvent to EventEmitter which accepts a caller-provided EventPayload subclass, and modifies TouchEventEmitter's dispatchPointerEvent method to use it so that the typed PointerEvent is actually sent through the event pipeline. Reviewed By: NickGerleman Differential Revision: D47351851 fbshipit-source-id: a6fdabbfc9b8287c564252f5cc7296fa75044a1e
1 parent c3f07d8 commit 6172988

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void TouchEventEmitter::dispatchPointerEvent(
7979
RawEvent::Category category) const {
8080
dispatchEvent(
8181
std::move(type),
82-
[event](jsi::Runtime &runtime) { return event.asJSIValue(runtime); },
82+
std::make_shared<PointerEvent>(event),
8383
priority,
8484
category);
8585
}
@@ -139,9 +139,7 @@ void TouchEventEmitter::onPointerDown(const PointerEvent &event) const {
139139
}
140140

141141
void TouchEventEmitter::onPointerMove(const PointerEvent &event) const {
142-
dispatchUniqueEvent("pointerMove", [event](jsi::Runtime &runtime) {
143-
return event.asJSIValue(runtime);
144-
});
142+
dispatchUniqueEvent("pointermove", std::make_shared<PointerEvent>(event));
145143
}
146144

147145
void TouchEventEmitter::onPointerUp(const PointerEvent &event) const {

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ void EventEmitter::dispatchEvent(
7474
const ValueFactory &payloadFactory,
7575
EventPriority priority,
7676
RawEvent::Category category) const {
77+
dispatchEvent(
78+
std::move(type),
79+
std::make_shared<ValueFactoryEventPayload>(payloadFactory),
80+
priority,
81+
category);
82+
}
83+
84+
void EventEmitter::dispatchEvent(
85+
std::string type,
86+
SharedEventPayload payload,
87+
EventPriority priority,
88+
RawEvent::Category category) const {
7789
SystraceSection s("EventEmitter::dispatchEvent", "type", type);
7890

7991
auto eventDispatcher = eventDispatcher_.lock();
@@ -84,7 +96,7 @@ void EventEmitter::dispatchEvent(
8496
eventDispatcher->dispatchEvent(
8597
RawEvent(
8698
normalizeEventType(std::move(type)),
87-
std::make_shared<ValueFactoryEventPayload>(payloadFactory),
99+
std::move(payload),
88100
eventTarget_,
89101
category),
90102
priority);
@@ -93,6 +105,14 @@ void EventEmitter::dispatchEvent(
93105
void EventEmitter::dispatchUniqueEvent(
94106
std::string type,
95107
const ValueFactory &payloadFactory) const {
108+
dispatchUniqueEvent(
109+
std::move(type),
110+
std::make_shared<ValueFactoryEventPayload>(payloadFactory));
111+
}
112+
113+
void EventEmitter::dispatchUniqueEvent(
114+
std::string type,
115+
SharedEventPayload payload) const {
96116
SystraceSection s("EventEmitter::dispatchUniqueEvent");
97117

98118
auto eventDispatcher = eventDispatcher_.lock();
@@ -102,7 +122,7 @@ void EventEmitter::dispatchUniqueEvent(
102122

103123
eventDispatcher->dispatchUniqueEvent(RawEvent(
104124
normalizeEventType(std::move(type)),
105-
std::make_shared<ValueFactoryEventPayload>(payloadFactory),
125+
std::move(payload),
106126
eventTarget_,
107127
RawEvent::Category::Continuous));
108128
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class EventEmitter {
8080
EventPriority priority = EventPriority::AsynchronousBatched,
8181
RawEvent::Category category = RawEvent::Category::Unspecified) const;
8282

83+
void dispatchEvent(
84+
std::string type,
85+
SharedEventPayload payload,
86+
EventPriority priority = EventPriority::AsynchronousBatched,
87+
RawEvent::Category category = RawEvent::Category::Unspecified) const;
88+
8389
void dispatchUniqueEvent(std::string type, const folly::dynamic &payload)
8490
const;
8591

@@ -88,6 +94,8 @@ class EventEmitter {
8894
const ValueFactory &payloadFactory =
8995
EventEmitter::defaultPayloadFactory()) const;
9096

97+
void dispatchUniqueEvent(std::string type, SharedEventPayload payload) const;
98+
9199
private:
92100
void toggleEventTargetOwnership_() const;
93101

0 commit comments

Comments
 (0)