Migrate FabricEventEmitter (#45717)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45717

# Changelog:
[Internal] -

As in the title.

Reviewed By: tdn120

Differential Revision: D60283894

fbshipit-source-id: 7a4ed8082e8fd458bea5dcf576623394c164b87a
This commit is contained in:
Ruslan Shestopalyuk
2024-07-27 22:23:14 -07:00
committed by Facebook GitHub Bot
parent 58a4e2ef14
commit 329ab64209
3 changed files with 65 additions and 75 deletions
@@ -2710,7 +2710,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 <init> (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
@@ -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");
}
}
@@ -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")
}
}