From 5f1134c8df35efbc83163ca0b7d200f1fd6b4904 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 21 Jan 2025 19:03:24 -0800 Subject: [PATCH] Fix execution of early InteropEvents (#48823) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48823 This diff is fixing the execution of Events that are sent early in the rendering of surfaces. This diff fixes a bug in the queueing of events that are built with not surfaceId (-1), the fixes is to call getSurfaceManagerForView() to retrieve the proper surfaceId (as we do in the execution of events) calling getSurfaceManagerForView() has a perf hit, we believe this won't be a problem because this method will only be called in edge cases (no surfaceId and early execution of events) changelog: [Android][Fixed] Fix execution of early InteropEvents Reviewed By: shwanton, lenaic Differential Revision: D68454811 fbshipit-source-id: a79be0b392004e645c48d1683bba774b6b597ca0 --- .../fabric/mounting/MountingManager.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 3aa8c930349..6f0cca01c97 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -330,14 +330,11 @@ public class MountingManager { @AnyThread @ThreadConfined(ANY) public @Nullable EventEmitterWrapper getEventEmitter(int surfaceId, int reactTag) { - SurfaceMountingManager surfaceMountingManager = - (surfaceId == ViewUtil.NO_SURFACE_ID - ? getSurfaceManagerForView(reactTag) - : getSurfaceManager(surfaceId)); - if (surfaceMountingManager == null) { + SurfaceMountingManager smm = getSurfaceMountingManager(surfaceId, reactTag); + if (smm == null) { return null; } - return surfaceMountingManager.getEventEmitter(reactTag); + return smm.getEventEmitter(reactTag); } /** @@ -434,11 +431,21 @@ public class MountingManager { boolean canCoalesceEvent, @Nullable WritableMap params, @EventCategoryDef int eventCategory) { - @Nullable SurfaceMountingManager smm = getSurfaceManager(surfaceId); + SurfaceMountingManager smm = getSurfaceMountingManager(surfaceId, reactTag); if (smm == null) { - // Cannot queue event without valid surface mountng manager. Do nothing here. + FLog.d( + TAG, + "Cannot queue event without valid surface mounting manager for tag: %d, surfaceId: %d", + reactTag, + surfaceId); return; } smm.enqueuePendingEvent(reactTag, eventName, canCoalesceEvent, params, eventCategory); } + + private @Nullable SurfaceMountingManager getSurfaceMountingManager(int surfaceId, int reactTag) { + return (surfaceId == ViewUtil.NO_SURFACE_ID + ? getSurfaceManagerForView(reactTag) + : getSurfaceManager(surfaceId)); + } }