From 082706ccd4fa6cd4c619f79b43a5f226ea256d0e Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 10 Jul 2024 04:17:55 -0700 Subject: [PATCH] remove event emitter from view preallocation (#45351) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45351 changelog: [internal] event emitter is always null during view preallocation. Let's just remove it completely from the method signature Reviewed By: rubennorte Differential Revision: D59522141 fbshipit-source-id: cb4f3b314607b4ee8b2209a8ab55e066ee7e075a --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 4 ++-- .../java/com/facebook/react/fabric/FabricUIManager.java | 2 -- .../react/fabric/mounting/SurfaceMountingManager.java | 4 +--- .../react/fabric/mounting/mountitems/MountItemFactory.kt | 5 +---- .../mounting/mountitems/PreAllocateViewMountItem.java | 6 +----- .../src/main/jni/react/fabric/FabricMountingManager.cpp | 7 +------ 6 files changed, 6 insertions(+), 22 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 094537dd7ff..be40313e243 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2803,7 +2803,7 @@ public class com/facebook/react/fabric/mounting/SurfaceMountingManager { public fun getViewExists (I)Z public fun isRootViewAttached ()Z public fun isStopped ()Z - public fun preallocateView (Ljava/lang/String;ILcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/fabric/events/EventEmitterWrapper;Z)V + public fun preallocateView (Ljava/lang/String;ILcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Z)V public fun printSurfaceState ()V public fun receiveCommand (IILcom/facebook/react/bridge/ReadableArray;)V public fun receiveCommand (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V @@ -2841,7 +2841,7 @@ public final class com/facebook/react/fabric/mounting/mountitems/MountItemFactor public static final fun createDispatchCommandMountItem (IIILcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; public static final fun createDispatchCommandMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; public static final fun createIntBufferBatchMountItem (I[I[Ljava/lang/Object;I)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; - public static final fun createPreAllocateViewMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/fabric/events/EventEmitterWrapper;Z)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; + public static final fun createPreAllocateViewMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Z)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; public static final fun createSendAccessibilityEventMountItem (III)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 74c0e64d188..160016d132c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -750,7 +750,6 @@ public class FabricUIManager final String componentName, @Nullable Object props, @Nullable Object stateWrapper, - @Nullable Object eventEmitterWrapper, boolean isLayoutable) { mMountItemDispatcher.addPreAllocateMountItem( @@ -760,7 +759,6 @@ public class FabricUIManager componentName, (ReadableMap) props, (StateWrapper) stateWrapper, - (EventEmitterWrapper) eventEmitterWrapper, isLayoutable)); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 421301fe3d1..813f9516e19 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -1238,7 +1238,6 @@ public class SurfaceMountingManager { int reactTag, @Nullable ReadableMap props, @Nullable StateWrapper stateWrapper, - @Nullable EventEmitterWrapper eventEmitterWrapper, boolean isLayoutable) { UiThreadUtil.assertOnUiThread(); @@ -1251,8 +1250,7 @@ public class SurfaceMountingManager { return; } - createViewUnsafe( - componentName, reactTag, props, stateWrapper, eventEmitterWrapper, isLayoutable); + createViewUnsafe(componentName, reactTag, props, stateWrapper, null, isLayoutable); } @AnyThread diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt index 80b72746444..f74ab4042ed 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt @@ -9,7 +9,6 @@ package com.facebook.react.fabric.mounting.mountitems import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap -import com.facebook.react.fabric.events.EventEmitterWrapper import com.facebook.react.uimanager.StateWrapper /** Factory class that expose creation of [MountItem] */ @@ -50,11 +49,9 @@ public object MountItemFactory { component: String, props: ReadableMap?, stateWrapper: StateWrapper?, - eventEmitterWrapper: EventEmitterWrapper?, isLayoutable: Boolean ): MountItem = - PreAllocateViewMountItem( - surfaceId, reactTag, component, props, stateWrapper, eventEmitterWrapper, isLayoutable) + PreAllocateViewMountItem(surfaceId, reactTag, component, props, stateWrapper, isLayoutable) /** * @return a [MountItem] that will be read and execute a collection of MountItems serialized in diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java index ea9f494a947..2dca9060a0c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java @@ -16,7 +16,6 @@ import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.fabric.mounting.MountingManager; import com.facebook.react.fabric.mounting.SurfaceMountingManager; import com.facebook.react.uimanager.StateWrapper; @@ -30,7 +29,6 @@ final class PreAllocateViewMountItem implements MountItem { private final int mReactTag; private final @Nullable ReadableMap mProps; private final @Nullable StateWrapper mStateWrapper; - private final @Nullable EventEmitterWrapper mEventEmitterWrapper; private final boolean mIsLayoutable; PreAllocateViewMountItem( @@ -39,13 +37,11 @@ final class PreAllocateViewMountItem implements MountItem { @NonNull String component, @Nullable ReadableMap props, @Nullable StateWrapper stateWrapper, - @Nullable EventEmitterWrapper eventEmitterWrapper, boolean isLayoutable) { mComponent = getFabricComponentName(component); mSurfaceId = surfaceId; mProps = props; mStateWrapper = stateWrapper; - mEventEmitterWrapper = eventEmitterWrapper; mReactTag = reactTag; mIsLayoutable = isLayoutable; } @@ -65,7 +61,7 @@ final class PreAllocateViewMountItem implements MountItem { return; } surfaceMountingManager.preallocateView( - mComponent, mReactTag, mProps, mStateWrapper, mEventEmitterWrapper, mIsLayoutable); + mComponent, mReactTag, mProps, mStateWrapper, mIsLayoutable); } @Override diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index 0246cb74f8d..ea6ed97c4b3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -817,8 +817,7 @@ void FabricMountingManager::maybePreallocateShadowView( static auto preallocateView = JFabricUIManager::javaClassStatic() - ->getMethod( + ->getMethod( "preallocateView"); // Do not hold onto Java object from C @@ -831,9 +830,6 @@ void FabricMountingManager::maybePreallocateShadowView( cStateWrapper->setState(shadowView.state); } - // Do not hold a reference to javaEventEmitter from the C++ side. - jni::local_ref javaEventEmitter = nullptr; - jni::local_ref props = getProps({}, shadowView); auto component = getPlatformComponentName(shadowView); @@ -845,7 +841,6 @@ void FabricMountingManager::maybePreallocateShadowView( component.get(), props.get(), (javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr), - (javaEventEmitter != nullptr ? javaEventEmitter.get() : nullptr), isLayoutableShadowNode); }