From 086c967286638deb9db21e4d62e6dca1fc1fba83 Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Thu, 30 Sep 2021 22:24:13 -0700 Subject: [PATCH] Use dispatch unique for events that can be coalesced Summary: Event merging or "coalescing" is done on Java side from Android, but Fabric also includes some Cxx logic to merge those events. Although Android doesn't need this logic in particular, it is important to follow this path to ensure these events (e.g. scroll) are dispatched as "continuous", allowing for correct prioritization in Concurrent Mode. `dispatchModernV2` selects between `dispatch` and `dispatchUnique` based on the `canBeCoalesced` parameter of the event, which is exactly what we need. The logic is only used in the "new" event dispatcher at the moment, so I wrapped it with feature flag to validate it doesn't cause any regressions. Changelog: [Android][Internal] - Try dispatching coalescing events as unique to Fabric Reviewed By: sammy-SC Differential Revision: D31272585 fbshipit-source-id: 6b67b61bd13fbff019d9eb8c5172bdd814a7b5b8 --- .../java/com/facebook/react/config/ReactFeatureFlags.java | 2 ++ .../react/uimanager/events/EventDispatcherImpl.java | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index ac4633995d9..7cf3f4237ee 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -101,4 +101,6 @@ public class ReactFeatureFlags { public static boolean insertZReorderBarriersOnViewGroupChildren = true; public static boolean enableScrollViewSnapToAlignmentProp = true; + + public static boolean useDispatchUniqueForCoalescableEvents = false; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java index a99d6b1eb31..c972fe03ad1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java @@ -13,6 +13,7 @@ import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.common.MapBuilder; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.modules.core.ChoreographerCompat; import com.facebook.react.modules.core.ReactChoreographer; import com.facebook.react.uimanager.common.UIManagerType; @@ -366,7 +367,12 @@ public class EventDispatcherImpl implements EventDispatcher, LifecycleEventListe } Systrace.endAsyncFlow( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, event.getEventName(), event.getUniqueID()); - event.dispatchModern(mReactEventEmitter); + + if (ReactFeatureFlags.useDispatchUniqueForCoalescableEvents) { + event.dispatchModernV2(mReactEventEmitter); + } else { + event.dispatchModern(mReactEventEmitter); + } event.dispose(); } clearEventsToDispatch();