Files
react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp
T
Samuel Susla 1866566d52 Introduce a way to specify React priority for events
Summary:
Changelog: [internal]

Introduce a way to specify React priority for events.
These APIs will be called from React here: https://github.com/facebook/react/blob/0e100ed00fb52cfd107db1d1081ef18fe4b9167f/packages/react-native-renderer/src/ReactFabricHostConfig.js#L345

React does similar thing on the web: https://github.com/facebook/react/blob/8ea11306ad473b26a2c899ef7a893d25413f3510/packages/react-dom/src/client/ReactDOMHostConfig.js#L378

Take a look at D28483983 that shows how React will be calling these APIs.

Reviewed By: JoshuaGross

Differential Revision: D28481260

fbshipit-source-id: c965a8aa0ba5192246c216046d49bcb046152a5a
2021-05-25 01:16:04 -07:00

63 lines
1.5 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "EventQueue.h"
#include "EventEmitter.h"
#include "ShadowNodeFamily.h"
namespace facebook {
namespace react {
EventQueueProcessor::EventQueueProcessor(
EventPipe eventPipe,
StatePipe statePipe)
: eventPipe_(std::move(eventPipe)), statePipe_(std::move(statePipe)) {}
void EventQueueProcessor::flushEvents(
jsi::Runtime &runtime,
std::vector<RawEvent> &&events) const {
{
std::lock_guard<std::mutex> lock(EventEmitter::DispatchMutex());
for (const auto &event : events) {
if (event.eventTarget) {
event.eventTarget->retain(runtime);
}
}
}
for (const auto &event : events) {
eventPipe_(
runtime,
event.eventTarget.get(),
event.type,
ReactEventPriority::Default,
event.payloadFactory);
}
// No need to lock `EventEmitter::DispatchMutex()` here.
// The mutex protects from a situation when the `instanceHandle` can be
// deallocated during accessing, but that's impossible at this point because
// we have a strong pointer to it.
for (const auto &event : events) {
if (event.eventTarget) {
event.eventTarget->release(runtime);
}
}
}
void EventQueueProcessor::flushStateUpdates(
std::vector<StateUpdate> &&states) const {
for (const auto &stateUpdate : states) {
statePipe_(stateUpdate);
}
}
} // namespace react
} // namespace facebook