diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index cdf0b0dcbd5986..1741440a9bc8fb 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2712,7 +2712,7 @@ public class com/facebook/react/fabric/events/EventEmitterWrapper { public fun dispatchUnique (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V } -public class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/react/uimanager/events/RCTModernEventEmitter { +public final class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/react/uimanager/events/RCTModernEventEmitter { public fun (Lcom/facebook/react/fabric/FabricUIManager;)V public fun receiveEvent (IILjava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V public fun receiveEvent (IILjava/lang/String;ZILcom/facebook/react/bridge/WritableMap;I)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java deleted file mode 100644 index b85e790fd164a7..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.fabric.events; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.WritableArray; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.fabric.FabricUIManager; -import com.facebook.react.uimanager.common.ViewUtil; -import com.facebook.react.uimanager.events.EventCategoryDef; -import com.facebook.react.uimanager.events.RCTModernEventEmitter; -import com.facebook.react.uimanager.events.TouchEvent; -import com.facebook.systrace.Systrace; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class FabricEventEmitter implements RCTModernEventEmitter { - - private final FabricUIManager mUIManager; - - public FabricEventEmitter(FabricUIManager uiManager) { - mUIManager = uiManager; - } - - @Override - public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap params) { - receiveEvent(ViewUtil.NO_SURFACE_ID, reactTag, eventName, params); - } - - @Override - public void receiveEvent( - int surfaceId, int reactTag, String eventName, @Nullable WritableMap params) { - receiveEvent(surfaceId, reactTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED); - } - - @Override - public void receiveEvent( - int surfaceId, - int reactTag, - String eventName, - boolean canCoalesceEvent, - int customCoalesceKey, - @Nullable WritableMap params, - @EventCategoryDef int category) { - Systrace.beginSection( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, - "FabricEventEmitter.receiveEvent('" + eventName + "')"); - try { - mUIManager.receiveEvent(surfaceId, reactTag, eventName, canCoalesceEvent, params, category); - } finally { - Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); - } - } - - /** Touches are dispatched by {@link #receiveTouches(TouchEvent)} */ - @Override - public void receiveTouches( - String eventName, WritableArray touches, WritableArray changedIndices) { - throw new UnsupportedOperationException( - "EventEmitter#receiveTouches is not supported by Fabric"); - } - - @Override - public void receiveTouches(TouchEvent event) { - // Calls are expected to go via TouchesHelper - throw new UnsupportedOperationException( - "EventEmitter#receiveTouches is not supported by Fabric"); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.kt new file mode 100644 index 00000000000000..2c85e1273d13bf --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric.events + +import com.facebook.react.bridge.WritableArray +import com.facebook.react.bridge.WritableMap +import com.facebook.react.fabric.FabricUIManager +import com.facebook.react.uimanager.common.ViewUtil +import com.facebook.react.uimanager.events.EventCategoryDef +import com.facebook.react.uimanager.events.RCTModernEventEmitter +import com.facebook.react.uimanager.events.TouchEvent +import com.facebook.systrace.Systrace + +public class FabricEventEmitter(private val uiManager: FabricUIManager) : RCTModernEventEmitter { + public override fun receiveEvent(reactTag: Int, eventName: String, params: WritableMap?): Unit { + receiveEvent(ViewUtil.NO_SURFACE_ID, reactTag, eventName, params) + } + + public override fun receiveEvent( + surfaceId: Int, + reactTag: Int, + eventName: String, + params: WritableMap? + ) { + receiveEvent(surfaceId, reactTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED) + } + + public override fun receiveEvent( + surfaceId: Int, + reactTag: Int, + eventName: String, + canCoalesceEvent: Boolean, + customCoalesceKey: Int, + params: WritableMap?, + @EventCategoryDef category: Int + ) { + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricEventEmitter.receiveEvent('$eventName')") + try { + uiManager.receiveEvent(surfaceId, reactTag, eventName, canCoalesceEvent, params, category) + } finally { + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE) + } + } + + /** Touches are dispatched by [.receiveTouches] */ + public override fun receiveTouches( + eventName: String, + touches: WritableArray, + changedIndices: WritableArray + ): Unit { + throw UnsupportedOperationException("EventEmitter#receiveTouches is not supported by Fabric") + } + + public override fun receiveTouches(event: TouchEvent): Unit { + // Calls are expected to go via TouchesHelper + throw UnsupportedOperationException("EventEmitter#receiveTouches is not supported by Fabric") + } +}