Skip to content

Commit

Permalink
Convert RCTModernEventEmitter (facebook#48466)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48466

# Changelog:
[Internal] -

As in the title.

Differential Revision: D67793108
  • Loading branch information
rshest authored and facebook-github-bot committed Jan 4, 2025
1 parent 6abcca8 commit c3490b8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ internal class EventAnimationDriver(
@JvmField internal var valueNode: ValueAnimatedNode
) : RCTModernEventEmitter {
@Deprecated("Deprecated in Java")
override fun receiveEvent(targetReactTag: Int, eventName: String, event: WritableMap?) =
receiveEvent(-1, targetReactTag, eventName, event)
override fun receiveEvent(targetTag: Int, eventName: String, params: WritableMap?) =
receiveEvent(-1, targetTag, eventName, params)

override fun receiveEvent(
surfaceId: Int,
targetTag: Int,
eventName: String,
event: WritableMap?
params: WritableMap?
) =
// We assume this event can't be coalesced. `customCoalesceKey` has no meaning in Fabric.
receiveEvent(surfaceId, targetTag, eventName, false, 0, event, EventCategoryDef.UNSPECIFIED)
receiveEvent(surfaceId, targetTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED)

@Deprecated("Deprecated in Java")
override fun receiveTouches(
Expand All @@ -47,7 +47,7 @@ internal class EventAnimationDriver(
}

@Deprecated("Deprecated in Java")
override fun receiveTouches(touchEvent: TouchEvent) {
override fun receiveTouches(event: TouchEvent) {
throw UnsupportedOperationException("receiveTouches is not support by native animated events")
}

Expand All @@ -57,13 +57,13 @@ internal class EventAnimationDriver(
eventName: String,
canCoalesceEvent: Boolean,
customCoalesceKey: Int,
event: WritableMap?,
params: WritableMap?,
@EventCategoryDef category: Int
) {
requireNotNull(event) { "Native animated events must have event data." }
requireNotNull(params) { "Native animated events must have event data." }

// Get the new value for the node by looking into the event map using the provided event path.
var currMap: ReadableMap? = event
var currMap: ReadableMap? = params
var currArray: ReadableArray? = null
for (i in 0 until eventPath.size - 1) {
if (currMap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import com.facebook.systrace.Systrace

public class FabricEventEmitter(private val uiManager: FabricUIManager) : RCTModernEventEmitter {
@Deprecated("Deprecated in Java")
public override fun receiveEvent(reactTag: Int, eventName: String, params: WritableMap?): Unit {
receiveEvent(ViewUtil.NO_SURFACE_ID, reactTag, eventName, params)
public override fun receiveEvent(targetTag: Int, eventName: String, params: WritableMap?): Unit {
receiveEvent(ViewUtil.NO_SURFACE_ID, targetTag, eventName, params)
}

public override fun receiveEvent(
surfaceId: Int,
reactTag: Int,
targetTag: Int,
eventName: String,
params: WritableMap?
) {
receiveEvent(surfaceId, reactTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED)
receiveEvent(surfaceId, targetTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED)
}

public override fun receiveEvent(
surfaceId: Int,
reactTag: Int,
targetTag: Int,
eventName: String,
canCoalesceEvent: Boolean,
customCoalesceKey: Int,
Expand All @@ -43,7 +43,7 @@ public class FabricEventEmitter(private val uiManager: FabricUIManager) : RCTMod
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricEventEmitter.receiveEvent('$eventName')")
try {
uiManager.receiveEvent(surfaceId, reactTag, eventName, canCoalesceEvent, params, category)
uiManager.receiveEvent(surfaceId, targetTag, eventName, canCoalesceEvent, params, category)
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.uimanager.events

import com.facebook.react.bridge.WritableMap

/**
* This is a transitional replacement for [RCTEventEmitter] that works with Fabric and non-Fabric
* renderers. [RCTEventEmitter] works with Fabric as well, but there are negative perf implications
* and it should be avoided.
*
* This interface will *also* be deleted in the distant future and be replaced with a new interface
* that doesn't need the old `receiveEvent` method at all. But for the foreseeable future, this is
* the recommended interface to use for EventEmitters.
*/
@Suppress("DEPRECATION")
public interface RCTModernEventEmitter : RCTEventEmitter {
public fun receiveEvent(surfaceId: Int, targetTag: Int, eventName: String, params: WritableMap?)

public fun receiveEvent(
surfaceId: Int,
targetTag: Int,
eventName: String,
canCoalesceEvent: Boolean,
customCoalesceKey: Int,
params: WritableMap?,
@EventCategoryDef category: Int
)

@Deprecated("Dispatch the TouchEvent using [EventDispatcher] instead")
public fun receiveTouches(event: TouchEvent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte
}

@Deprecated("Please use RCTModernEventEmitter")
override fun receiveEvent(targetReactTag: Int, eventName: String, event: WritableMap?) {
receiveEvent(-1, targetReactTag, eventName, event)
override fun receiveEvent(targetReactTag: Int, eventName: String, params: WritableMap?) {
receiveEvent(-1, targetReactTag, eventName, params)
}

override fun receiveEvent(
surfaceId: Int,
targetTag: Int,
eventName: String,
event: WritableMap?
params: WritableMap?
) {
// We assume this event can't be coalesced. `customCoalesceKey` has no meaning in Fabric.
receiveEvent(surfaceId, targetTag, eventName, false, 0, event, EventCategoryDef.UNSPECIFIED)
receiveEvent(surfaceId, targetTag, eventName, false, 0, params, EventCategoryDef.UNSPECIFIED)
}

@Deprecated("Please use RCTModernEventEmitter")
Expand Down Expand Up @@ -108,25 +108,19 @@ internal class ReactEventEmitter(private val reactContext: ReactApplicationConte

override fun receiveEvent(
surfaceId: Int,
targetReactTag: Int,
targetTag: Int,
eventName: String,
canCoalesceEvent: Boolean,
customCoalesceKey: Int,
event: WritableMap?,
params: WritableMap?,
@EventCategoryDef category: Int
) {
@UIManagerType val uiManagerType = getUIManagerType(targetReactTag, surfaceId)
@UIManagerType val uiManagerType = getUIManagerType(targetTag, surfaceId)
if (uiManagerType == UIManagerType.FABRIC) {
fabricEventEmitter?.receiveEvent(
surfaceId,
targetReactTag,
eventName,
canCoalesceEvent,
customCoalesceKey,
event,
category)
surfaceId, targetTag, eventName, canCoalesceEvent, customCoalesceKey, params, category)
} else if (uiManagerType == UIManagerType.DEFAULT) {
ensureDefaultEventEmitter()?.receiveEvent(targetReactTag, eventName, event)
ensureDefaultEventEmitter()?.receiveEvent(targetTag, eventName, params)
}
}

Expand Down

0 comments on commit c3490b8

Please sign in to comment.