Define continuous and idle priority for raw events and expose them to React via nativeFabricUIManager (#50627)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50627

Changelog: [internal]

This defines 2 new priorities in Fabric, matching the definitions in React:
* Continuous
* Idle

They're exposed to React via 2 new properties in `nativeFabricUIManager`: `unstable_ContinuousEventPriority` and `unstable_IdleEventPriority`.

It also adds the mapping from the raw event priorities to the Fabric event priorities.

This change doesn't have any effect at the moment. For these to come into effect, we need to:
1. Fix the mapping between Fabric priorities and React priorities in the React repository. See https://github.com/facebook/react/pull/32847
2. Enable the `fixMappingOfEventPrioritiesBetweenFabricAndReact` feature flag.

Reviewed By: javache

Differential Revision: D72791968

fbshipit-source-id: 525b6e5c99dc0ddc1e5c60fdb5b73f0555e5f0d3
This commit is contained in:
Rubén Norte
2025-04-10 13:12:21 -07:00
committed by Facebook GitHub Bot
parent 834a6338c8
commit 02bf24b1d8
5 changed files with 22 additions and 2 deletions
@@ -10,7 +10,6 @@
#include "AndroidEventBeat.h"
#include "ComponentFactory.h"
#include "EventBeatManager.h"
#include "EventEmitterWrapper.h"
#include "FabricMountingManager.h"
#include <cxxreact/TraceSection.h>
@@ -55,6 +55,8 @@ void EventQueueProcessor::flushEvents(
return ReactEventPriority::Discrete;
case RawEvent::Category::Continuous:
return ReactEventPriority::Continuous;
case RawEvent::Category::Idle:
return ReactEventPriority::Idle;
case RawEvent::Category::Unspecified:
return hasContinuousEventStarted_ ? ReactEventPriority::Continuous
: ReactEventPriority::Default;
@@ -56,7 +56,13 @@ struct RawEvent {
* Forces continuous type for the event. Regardless if continuous event
* isn't ongoing.
*/
Continuous = 4
Continuous = 4,
/*
* Priority for events that can be processed in idle times or in the
* background.
*/
Idle = 5,
};
RawEvent(
@@ -30,6 +30,11 @@ enum class ReactEventPriority {
* scrolling.
*/
Continuous,
/*
* Other events that can be processed in the background.
*/
Idle,
};
static constexpr std::underlying_type<ReactEventPriority>::type serialize(
@@ -747,6 +747,14 @@ jsi::Value UIManagerBinding::get(
return {serialize(ReactEventPriority::Discrete)};
}
if (methodName == "unstable_ContinuousEventPriority") {
return {serialize(ReactEventPriority::Continuous)};
}
if (methodName == "unstable_IdleEventPriority") {
return {serialize(ReactEventPriority::Idle)};
}
if (methodName == "findShadowNodeByTag_DEPRECATED") {
auto paramCount = 1;
return jsi::Function::createFromHostFunction(