mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Enable synchronous state update dispatching behind a flag (#43580)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43580 Changelog: [internal] This introduces a new feature flag to commit state updates synchronously from the UI thread (generally) instead of dispatching them to the JS thread to be processed there. We can do this now because we introduced a UI consistency mechanism in D55024832 to JS would see a consistent revision during the execution of a specific task. Reviewed By: sammy-SC Differential Revision: D55083029 fbshipit-source-id: 8aa84ddaee383f098252fa679cfb07012ba29bf8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
04562dd48a
commit
f446cf6464
+7
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<20c445fde7a1c2607b58b7797346431f>>
|
||||
* @generated SignedSource<<e3cfdd93315067ed37e7cf93aa60af74>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -76,6 +76,12 @@ public object ReactNativeFeatureFlags {
|
||||
@JvmStatic
|
||||
public fun enableSpannableBuildingUnification(): Boolean = accessor.enableSpannableBuildingUnification()
|
||||
|
||||
/**
|
||||
* Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun enableSynchronousStateUpdates(): Boolean = accessor.enableSynchronousStateUpdates()
|
||||
|
||||
/**
|
||||
* Ensures that JavaScript always has a consistent view of the state of the UI (e.g.: commits done in other threads are not immediately propagated to JS during its execution).
|
||||
*/
|
||||
|
||||
+11
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<6e973dcdcdfae14c77a6130207333551>>
|
||||
* @generated SignedSource<<9184044883f829855c2de9db42566287>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,6 +28,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
|
||||
private var enableMicrotasksCache: Boolean? = null
|
||||
private var enableMountHooksAndroidCache: Boolean? = null
|
||||
private var enableSpannableBuildingUnificationCache: Boolean? = null
|
||||
private var enableSynchronousStateUpdatesCache: Boolean? = null
|
||||
private var enableUIConsistencyCache: Boolean? = null
|
||||
private var inspectorEnableCxxInspectorPackagerConnectionCache: Boolean? = null
|
||||
private var inspectorEnableModernCDPRegistryCache: Boolean? = null
|
||||
@@ -105,6 +106,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
|
||||
return cached
|
||||
}
|
||||
|
||||
override fun enableSynchronousStateUpdates(): Boolean {
|
||||
var cached = enableSynchronousStateUpdatesCache
|
||||
if (cached == null) {
|
||||
cached = ReactNativeFeatureFlagsCxxInterop.enableSynchronousStateUpdates()
|
||||
enableSynchronousStateUpdatesCache = cached
|
||||
}
|
||||
return cached
|
||||
}
|
||||
|
||||
override fun enableUIConsistency(): Boolean {
|
||||
var cached = enableUIConsistencyCache
|
||||
if (cached == null) {
|
||||
|
||||
+3
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<0d34567fc05555ae401e7f5180dc8771>>
|
||||
* @generated SignedSource<<4154c0f81f2e5ad7ff03e252c4aa965c>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -44,6 +44,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
|
||||
|
||||
@DoNotStrip @JvmStatic public external fun enableSpannableBuildingUnification(): Boolean
|
||||
|
||||
@DoNotStrip @JvmStatic public external fun enableSynchronousStateUpdates(): Boolean
|
||||
|
||||
@DoNotStrip @JvmStatic public external fun enableUIConsistency(): Boolean
|
||||
|
||||
@DoNotStrip @JvmStatic public external fun inspectorEnableCxxInspectorPackagerConnection(): Boolean
|
||||
|
||||
+3
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<cfb3e4f5d83a939f4b034bc62762837e>>
|
||||
* @generated SignedSource<<c903b5aa8d70665c1104baa6670f8cb1>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,6 +39,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
|
||||
|
||||
override fun enableSpannableBuildingUnification(): Boolean = false
|
||||
|
||||
override fun enableSynchronousStateUpdates(): Boolean = false
|
||||
|
||||
override fun enableUIConsistency(): Boolean = false
|
||||
|
||||
override fun inspectorEnableCxxInspectorPackagerConnection(): Boolean = false
|
||||
|
||||
+12
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<8908de9b9d0186f1916d8b55d5854cb2>>
|
||||
* @generated SignedSource<<c087df804587a9a02a0547684d0e9c92>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -32,6 +32,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
|
||||
private var enableMicrotasksCache: Boolean? = null
|
||||
private var enableMountHooksAndroidCache: Boolean? = null
|
||||
private var enableSpannableBuildingUnificationCache: Boolean? = null
|
||||
private var enableSynchronousStateUpdatesCache: Boolean? = null
|
||||
private var enableUIConsistencyCache: Boolean? = null
|
||||
private var inspectorEnableCxxInspectorPackagerConnectionCache: Boolean? = null
|
||||
private var inspectorEnableModernCDPRegistryCache: Boolean? = null
|
||||
@@ -117,6 +118,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
|
||||
return cached
|
||||
}
|
||||
|
||||
override fun enableSynchronousStateUpdates(): Boolean {
|
||||
var cached = enableSynchronousStateUpdatesCache
|
||||
if (cached == null) {
|
||||
cached = currentProvider.enableSynchronousStateUpdates()
|
||||
accessedFeatureFlags.add("enableSynchronousStateUpdates")
|
||||
enableSynchronousStateUpdatesCache = cached
|
||||
}
|
||||
return cached
|
||||
}
|
||||
|
||||
override fun enableUIConsistency(): Boolean {
|
||||
var cached = enableUIConsistencyCache
|
||||
if (cached == null) {
|
||||
|
||||
+3
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<7555a704535615fcea44c1261095419a>>
|
||||
* @generated SignedSource<<c39073091ea96d16a352d00def1b5532>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,6 +39,8 @@ public interface ReactNativeFeatureFlagsProvider {
|
||||
|
||||
@DoNotStrip public fun enableSpannableBuildingUnification(): Boolean
|
||||
|
||||
@DoNotStrip public fun enableSynchronousStateUpdates(): Boolean
|
||||
|
||||
@DoNotStrip public fun enableUIConsistency(): Boolean
|
||||
|
||||
@DoNotStrip public fun inspectorEnableCxxInspectorPackagerConnection(): Boolean
|
||||
|
||||
+15
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<e6f57d186226377e4558f633433aa1fc>>
|
||||
* @generated SignedSource<<db9ab5f48de2fdbee406ddea10125feb>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,12 @@ class ReactNativeFeatureFlagsProviderHolder
|
||||
return method(javaProvider_);
|
||||
}
|
||||
|
||||
bool enableSynchronousStateUpdates() override {
|
||||
static const auto method =
|
||||
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableSynchronousStateUpdates");
|
||||
return method(javaProvider_);
|
||||
}
|
||||
|
||||
bool enableUIConsistency() override {
|
||||
static const auto method =
|
||||
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableUIConsistency");
|
||||
@@ -155,6 +161,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableSpannableBuildingUnification(
|
||||
return ReactNativeFeatureFlags::enableSpannableBuildingUnification();
|
||||
}
|
||||
|
||||
bool JReactNativeFeatureFlagsCxxInterop::enableSynchronousStateUpdates(
|
||||
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
|
||||
return ReactNativeFeatureFlags::enableSynchronousStateUpdates();
|
||||
}
|
||||
|
||||
bool JReactNativeFeatureFlagsCxxInterop::enableUIConsistency(
|
||||
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
|
||||
return ReactNativeFeatureFlags::enableUIConsistency();
|
||||
@@ -216,6 +227,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
|
||||
makeNativeMethod(
|
||||
"enableSpannableBuildingUnification",
|
||||
JReactNativeFeatureFlagsCxxInterop::enableSpannableBuildingUnification),
|
||||
makeNativeMethod(
|
||||
"enableSynchronousStateUpdates",
|
||||
JReactNativeFeatureFlagsCxxInterop::enableSynchronousStateUpdates),
|
||||
makeNativeMethod(
|
||||
"enableUIConsistency",
|
||||
JReactNativeFeatureFlagsCxxInterop::enableUIConsistency),
|
||||
|
||||
+4
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<a90ff7ce4734046fd9aab1c501ca22b4>>
|
||||
* @generated SignedSource<<6b33129341a4b68cdbbdbce9f57e4d63>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -54,6 +54,9 @@ class JReactNativeFeatureFlagsCxxInterop
|
||||
static bool enableSpannableBuildingUnification(
|
||||
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
|
||||
|
||||
static bool enableSynchronousStateUpdates(
|
||||
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
|
||||
|
||||
static bool enableUIConsistency(
|
||||
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<a5c58cc8c0294fd073f43fda88b908f8>>
|
||||
* @generated SignedSource<<56f79a4cb62a993f9c3a8ea01eed2ab6>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -53,6 +53,10 @@ bool ReactNativeFeatureFlags::enableSpannableBuildingUnification() {
|
||||
return getAccessor().enableSpannableBuildingUnification();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlags::enableSynchronousStateUpdates() {
|
||||
return getAccessor().enableSynchronousStateUpdates();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlags::enableUIConsistency() {
|
||||
return getAccessor().enableUIConsistency();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<e94d55bad5f8bf6cf933ddc50e3b4886>>
|
||||
* @generated SignedSource<<bab6aad25607059d465d6c80711a4adf>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -77,6 +77,11 @@ class ReactNativeFeatureFlags {
|
||||
*/
|
||||
RN_EXPORT static bool enableSpannableBuildingUnification();
|
||||
|
||||
/**
|
||||
* Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).
|
||||
*/
|
||||
RN_EXPORT static bool enableSynchronousStateUpdates();
|
||||
|
||||
/**
|
||||
* Ensures that JavaScript always has a consistent view of the state of the UI (e.g.: commits done in other threads are not immediately propagated to JS during its execution).
|
||||
*/
|
||||
|
||||
+23
-5
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<2ff39fd4c8330ddca994fc40cdeaaf4c>>
|
||||
* @generated SignedSource<<5b42b33319369b7936662a2608794ba5>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -173,6 +173,24 @@ bool ReactNativeFeatureFlagsAccessor::enableSpannableBuildingUnification() {
|
||||
return flagValue.value();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlagsAccessor::enableSynchronousStateUpdates() {
|
||||
auto flagValue = enableSynchronousStateUpdates_.load();
|
||||
|
||||
if (!flagValue.has_value()) {
|
||||
// This block is not exclusive but it is not necessary.
|
||||
// If multiple threads try to initialize the feature flag, we would only
|
||||
// be accessing the provider multiple times but the end state of this
|
||||
// instance and the returned flag value would be the same.
|
||||
|
||||
markFlagAsAccessed(8, "enableSynchronousStateUpdates");
|
||||
|
||||
flagValue = currentProvider_->enableSynchronousStateUpdates();
|
||||
enableSynchronousStateUpdates_ = flagValue;
|
||||
}
|
||||
|
||||
return flagValue.value();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlagsAccessor::enableUIConsistency() {
|
||||
auto flagValue = enableUIConsistency_.load();
|
||||
|
||||
@@ -182,7 +200,7 @@ bool ReactNativeFeatureFlagsAccessor::enableUIConsistency() {
|
||||
// be accessing the provider multiple times but the end state of this
|
||||
// instance and the returned flag value would be the same.
|
||||
|
||||
markFlagAsAccessed(8, "enableUIConsistency");
|
||||
markFlagAsAccessed(9, "enableUIConsistency");
|
||||
|
||||
flagValue = currentProvider_->enableUIConsistency();
|
||||
enableUIConsistency_ = flagValue;
|
||||
@@ -200,7 +218,7 @@ bool ReactNativeFeatureFlagsAccessor::inspectorEnableCxxInspectorPackagerConnect
|
||||
// be accessing the provider multiple times but the end state of this
|
||||
// instance and the returned flag value would be the same.
|
||||
|
||||
markFlagAsAccessed(9, "inspectorEnableCxxInspectorPackagerConnection");
|
||||
markFlagAsAccessed(10, "inspectorEnableCxxInspectorPackagerConnection");
|
||||
|
||||
flagValue = currentProvider_->inspectorEnableCxxInspectorPackagerConnection();
|
||||
inspectorEnableCxxInspectorPackagerConnection_ = flagValue;
|
||||
@@ -218,7 +236,7 @@ bool ReactNativeFeatureFlagsAccessor::inspectorEnableModernCDPRegistry() {
|
||||
// be accessing the provider multiple times but the end state of this
|
||||
// instance and the returned flag value would be the same.
|
||||
|
||||
markFlagAsAccessed(10, "inspectorEnableModernCDPRegistry");
|
||||
markFlagAsAccessed(11, "inspectorEnableModernCDPRegistry");
|
||||
|
||||
flagValue = currentProvider_->inspectorEnableModernCDPRegistry();
|
||||
inspectorEnableModernCDPRegistry_ = flagValue;
|
||||
@@ -236,7 +254,7 @@ bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() {
|
||||
// be accessing the provider multiple times but the end state of this
|
||||
// instance and the returned flag value would be the same.
|
||||
|
||||
markFlagAsAccessed(11, "useModernRuntimeScheduler");
|
||||
markFlagAsAccessed(12, "useModernRuntimeScheduler");
|
||||
|
||||
flagValue = currentProvider_->useModernRuntimeScheduler();
|
||||
useModernRuntimeScheduler_ = flagValue;
|
||||
|
||||
+4
-2
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<a8e0d8c5bc041f814bffb1701a124646>>
|
||||
* @generated SignedSource<<a508f23dce88a9c186d6bd84e65b3af7>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,6 +39,7 @@ class ReactNativeFeatureFlagsAccessor {
|
||||
bool enableMicrotasks();
|
||||
bool enableMountHooksAndroid();
|
||||
bool enableSpannableBuildingUnification();
|
||||
bool enableSynchronousStateUpdates();
|
||||
bool enableUIConsistency();
|
||||
bool inspectorEnableCxxInspectorPackagerConnection();
|
||||
bool inspectorEnableModernCDPRegistry();
|
||||
@@ -53,7 +54,7 @@ class ReactNativeFeatureFlagsAccessor {
|
||||
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
|
||||
bool wasOverridden_;
|
||||
|
||||
std::array<std::atomic<const char*>, 12> accessedFeatureFlags_;
|
||||
std::array<std::atomic<const char*>, 13> accessedFeatureFlags_;
|
||||
|
||||
std::atomic<std::optional<bool>> commonTestFlag_;
|
||||
std::atomic<std::optional<bool>> batchRenderingUpdatesInEventLoop_;
|
||||
@@ -63,6 +64,7 @@ class ReactNativeFeatureFlagsAccessor {
|
||||
std::atomic<std::optional<bool>> enableMicrotasks_;
|
||||
std::atomic<std::optional<bool>> enableMountHooksAndroid_;
|
||||
std::atomic<std::optional<bool>> enableSpannableBuildingUnification_;
|
||||
std::atomic<std::optional<bool>> enableSynchronousStateUpdates_;
|
||||
std::atomic<std::optional<bool>> enableUIConsistency_;
|
||||
std::atomic<std::optional<bool>> inspectorEnableCxxInspectorPackagerConnection_;
|
||||
std::atomic<std::optional<bool>> inspectorEnableModernCDPRegistry_;
|
||||
|
||||
+5
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<1450d89abc68821fb348574016874719>>
|
||||
* @generated SignedSource<<9fd009411ce19224a3102d2713b0b042>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -59,6 +59,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enableSynchronousStateUpdates() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enableUIConsistency() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<d369db4d7cd374081941bff6c6f3e08f>>
|
||||
* @generated SignedSource<<7384eeb8615a45b79cdcceb731d98e9d>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -33,6 +33,7 @@ class ReactNativeFeatureFlagsProvider {
|
||||
virtual bool enableMicrotasks() = 0;
|
||||
virtual bool enableMountHooksAndroid() = 0;
|
||||
virtual bool enableSpannableBuildingUnification() = 0;
|
||||
virtual bool enableSynchronousStateUpdates() = 0;
|
||||
virtual bool enableUIConsistency() = 0;
|
||||
virtual bool inspectorEnableCxxInspectorPackagerConnection() = 0;
|
||||
virtual bool inspectorEnableModernCDPRegistry() = 0;
|
||||
|
||||
+6
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<7e09a7ad1d178850bdcf73da3eb5623b>>
|
||||
* @generated SignedSource<<08ed8c4c27411ba5a04acb314eb36b63>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -77,6 +77,11 @@ bool NativeReactNativeFeatureFlags::enableSpannableBuildingUnification(
|
||||
return ReactNativeFeatureFlags::enableSpannableBuildingUnification();
|
||||
}
|
||||
|
||||
bool NativeReactNativeFeatureFlags::enableSynchronousStateUpdates(
|
||||
jsi::Runtime& /*runtime*/) {
|
||||
return ReactNativeFeatureFlags::enableSynchronousStateUpdates();
|
||||
}
|
||||
|
||||
bool NativeReactNativeFeatureFlags::enableUIConsistency(
|
||||
jsi::Runtime& /*runtime*/) {
|
||||
return ReactNativeFeatureFlags::enableUIConsistency();
|
||||
|
||||
+3
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<a356c9a406454c7591fbfe23edeeaee6>>
|
||||
* @generated SignedSource<<adcc82e9ad406a40cfaddaad816fb0f0>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -51,6 +51,8 @@ class NativeReactNativeFeatureFlags
|
||||
|
||||
bool enableSpannableBuildingUnification(jsi::Runtime& runtime);
|
||||
|
||||
bool enableSynchronousStateUpdates(jsi::Runtime& runtime);
|
||||
|
||||
bool enableUIConsistency(jsi::Runtime& runtime);
|
||||
|
||||
bool inspectorEnableCxxInspectorPackagerConnection(jsi::Runtime& runtime);
|
||||
|
||||
@@ -25,6 +25,7 @@ target_link_libraries(react_render_core
|
||||
logger
|
||||
react_config
|
||||
react_debug
|
||||
react_featureflags
|
||||
react_render_debug
|
||||
react_render_graphics
|
||||
react_render_mapbuffer
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "EventDispatcher.h"
|
||||
#include <cxxreact/JSExecutor.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/core/StateUpdate.h>
|
||||
#include "EventLogger.h"
|
||||
|
||||
@@ -19,11 +20,13 @@ EventDispatcher::EventDispatcher(
|
||||
const EventQueueProcessor& eventProcessor,
|
||||
const EventBeat::Factory& asynchronousEventBeatFactory,
|
||||
const EventBeat::SharedOwnerBox& ownerBox,
|
||||
RuntimeScheduler& runtimeScheduler)
|
||||
RuntimeScheduler& runtimeScheduler,
|
||||
StatePipe statePipe)
|
||||
: eventQueue_(EventQueue(
|
||||
eventProcessor,
|
||||
asynchronousEventBeatFactory(ownerBox),
|
||||
runtimeScheduler)) {}
|
||||
runtimeScheduler)),
|
||||
statePipe_(std::move(statePipe)) {}
|
||||
|
||||
void EventDispatcher::dispatchEvent(RawEvent&& rawEvent) const {
|
||||
// Allows the event listener to interrupt default event dispatch
|
||||
@@ -43,7 +46,11 @@ void EventDispatcher::experimental_flushSync() const {
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchStateUpdate(StateUpdate&& stateUpdate) const {
|
||||
eventQueue_.enqueueStateUpdate(std::move(stateUpdate));
|
||||
if (ReactNativeFeatureFlags::enableSynchronousStateUpdates()) {
|
||||
statePipe_(stateUpdate);
|
||||
} else {
|
||||
eventQueue_.enqueueStateUpdate(std::move(stateUpdate));
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchUniqueEvent(RawEvent&& rawEvent) const {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <react/renderer/core/EventListener.h>
|
||||
#include <react/renderer/core/EventQueue.h>
|
||||
#include <react/renderer/core/EventQueueProcessor.h>
|
||||
#include <react/renderer/core/StatePipe.h>
|
||||
#include <react/renderer/core/StateUpdate.h>
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -31,7 +32,8 @@ class EventDispatcher {
|
||||
const EventQueueProcessor& eventProcessor,
|
||||
const EventBeat::Factory& asynchronousEventBeatFactory,
|
||||
const EventBeat::SharedOwnerBox& ownerBox,
|
||||
RuntimeScheduler& runtimeScheduler);
|
||||
RuntimeScheduler& runtimeScheduler,
|
||||
StatePipe statePipe);
|
||||
|
||||
/*
|
||||
* Dispatches a raw event with given priority using event-delivery pipe.
|
||||
@@ -69,6 +71,7 @@ class EventDispatcher {
|
||||
|
||||
private:
|
||||
EventQueue eventQueue_;
|
||||
const StatePipe statePipe_;
|
||||
|
||||
mutable EventListenerContainer eventListeners_;
|
||||
};
|
||||
|
||||
@@ -91,7 +91,8 @@ Scheduler::Scheduler(
|
||||
EventQueueProcessor(eventPipe, eventPipeConclusion, statePipe),
|
||||
schedulerToolbox.asynchronousEventBeatFactory,
|
||||
eventOwnerBox,
|
||||
*runtimeScheduler);
|
||||
*runtimeScheduler,
|
||||
statePipe);
|
||||
|
||||
// Casting to `std::shared_ptr<EventDispatcher const>`.
|
||||
auto eventDispatcher =
|
||||
|
||||
@@ -67,6 +67,11 @@ const definitions: FeatureFlagDefinitions = {
|
||||
description:
|
||||
'Uses new, deduplicated logic for constructing Android Spannables from text fragments',
|
||||
},
|
||||
enableSynchronousStateUpdates: {
|
||||
defaultValue: false,
|
||||
description:
|
||||
'Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).',
|
||||
},
|
||||
enableUIConsistency: {
|
||||
defaultValue: false,
|
||||
description:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<c653f884a1ebb7556d0f59a4fdcf2fed>>
|
||||
* @generated SignedSource<<366b36d877532c93aa6e5a97b85edd06>>
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,7 @@ export type ReactNativeFeatureFlags = {
|
||||
enableMicrotasks: Getter<boolean>,
|
||||
enableMountHooksAndroid: Getter<boolean>,
|
||||
enableSpannableBuildingUnification: Getter<boolean>,
|
||||
enableSynchronousStateUpdates: Getter<boolean>,
|
||||
enableUIConsistency: Getter<boolean>,
|
||||
inspectorEnableCxxInspectorPackagerConnection: Getter<boolean>,
|
||||
inspectorEnableModernCDPRegistry: Getter<boolean>,
|
||||
@@ -126,6 +127,10 @@ export const enableMountHooksAndroid: Getter<boolean> = createNativeFlagGetter('
|
||||
* Uses new, deduplicated logic for constructing Android Spannables from text fragments
|
||||
*/
|
||||
export const enableSpannableBuildingUnification: Getter<boolean> = createNativeFlagGetter('enableSpannableBuildingUnification', false);
|
||||
/**
|
||||
* Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).
|
||||
*/
|
||||
export const enableSynchronousStateUpdates: Getter<boolean> = createNativeFlagGetter('enableSynchronousStateUpdates', false);
|
||||
/**
|
||||
* Ensures that JavaScript always has a consistent view of the state of the UI (e.g.: commits done in other threads are not immediately propagated to JS during its execution).
|
||||
*/
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<2f4c06a0e456d55a4bbd6b8c48c7f22d>>
|
||||
* @generated SignedSource<<0d744f7a8519800a42cb0c3957862775>>
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface Spec extends TurboModule {
|
||||
+enableMicrotasks?: () => boolean;
|
||||
+enableMountHooksAndroid?: () => boolean;
|
||||
+enableSpannableBuildingUnification?: () => boolean;
|
||||
+enableSynchronousStateUpdates?: () => boolean;
|
||||
+enableUIConsistency?: () => boolean;
|
||||
+inspectorEnableCxxInspectorPackagerConnection?: () => boolean;
|
||||
+inspectorEnableModernCDPRegistry?: () => boolean;
|
||||
|
||||
Reference in New Issue
Block a user