Skip to content

Commit

Permalink
Migrate FabricEventEmitter
Browse files Browse the repository at this point in the history
Differential Revision: D60283894
  • Loading branch information
rshest authored and facebook-github-bot committed Jul 27, 2024
1 parent 6d3d286 commit 6da7363
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 6da7363

Please sign in to comment.