From 02bf24b1d8b97deda22d62bcfb0a858863f7871c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 10 Apr 2025 13:12:21 -0700 Subject: [PATCH] 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 --- .../src/main/jni/react/fabric/FabricUIManagerBinding.cpp | 1 - .../react/renderer/core/EventQueueProcessor.cpp | 2 ++ .../ReactCommon/react/renderer/core/RawEvent.h | 8 +++++++- .../ReactCommon/react/renderer/core/ReactEventPriority.h | 5 +++++ .../react/renderer/uimanager/UIManagerBinding.cpp | 8 ++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp index b3813b0a0ed..5a00be8aee2 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp @@ -10,7 +10,6 @@ #include "AndroidEventBeat.h" #include "ComponentFactory.h" #include "EventBeatManager.h" -#include "EventEmitterWrapper.h" #include "FabricMountingManager.h" #include diff --git a/packages/react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp b/packages/react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp index ce1485b3ac1..7d268e2c204 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp @@ -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; diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawEvent.h b/packages/react-native/ReactCommon/react/renderer/core/RawEvent.h index c79aca59aa9..e701c12d869 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawEvent.h +++ b/packages/react-native/ReactCommon/react/renderer/core/RawEvent.h @@ -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( diff --git a/packages/react-native/ReactCommon/react/renderer/core/ReactEventPriority.h b/packages/react-native/ReactCommon/react/renderer/core/ReactEventPriority.h index 741084fe67b..f85a9a01b7b 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ReactEventPriority.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ReactEventPriority.h @@ -30,6 +30,11 @@ enum class ReactEventPriority { * scrolling. */ Continuous, + + /* + * Other events that can be processed in the background. + */ + Idle, }; static constexpr std::underlying_type::type serialize( diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index dddcd52e2de..c5baaf76cfe 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -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(