Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlinify EventEmitterWrapper #48489

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2669,11 +2669,11 @@ public final class com/facebook/react/fabric/events/EventBeatManager : com/faceb
public fun onBatchEventDispatched ()V
}

public class com/facebook/react/fabric/events/EventEmitterWrapper : com/facebook/jni/HybridClassBase {
public fun destroy ()V
public fun dispatch (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;I)V
public fun dispatchEventSynchronously (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
public fun dispatchUnique (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
public final class com/facebook/react/fabric/events/EventEmitterWrapper : com/facebook/jni/HybridClassBase {
public final fun destroy ()V
public final fun dispatch (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;I)V
public final fun dispatchEventSynchronously (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
public final fun dispatchUnique (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
}

public final class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/react/uimanager/events/RCTModernEventEmitter {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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 android.annotation.SuppressLint
import com.facebook.jni.HybridClassBase
import com.facebook.proguard.annotations.DoNotStripAny
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.WritableMap
import com.facebook.react.fabric.FabricSoLoader.staticInit
import com.facebook.react.uimanager.events.EventCategoryDef

/**
* This class holds reference to the C++ EventEmitter object. Instances of this class are created in
* FabricMountingManager.cpp, where the pointer to the C++ event emitter is set.
*/
@DoNotStripAny
@SuppressLint("MissingNativeLoadLibrary")
public class EventEmitterWrapper private constructor() : HybridClassBase() {
private external fun dispatchEvent(
eventName: String,
params: NativeMap?,
@EventCategoryDef category: Int
)

private external fun dispatchEventSynchronously(eventName: String, params: NativeMap?)

private external fun dispatchUniqueEvent(eventName: String, params: NativeMap?)

/**
* Invokes the execution of the C++ EventEmitter.
*
* @param eventName [String] name of the event to execute.
* @param params [WritableMap] payload of the event
*/
@Synchronized
public fun dispatch(
eventName: String,
params: WritableMap?,
@EventCategoryDef eventCategory: Int
) {
if (!isValid) {
return
}
dispatchEvent(eventName, params as NativeMap?, eventCategory)
}

@Synchronized
public fun dispatchEventSynchronously(eventName: String, params: WritableMap?) {
if (!isValid) {
return
}
dispatchEventSynchronously(eventName, params as NativeMap?)
}

/**
* Invokes the execution of the C++ EventEmitter. C++ will coalesce events sent to the same
* target.
*
* @param eventName [String] name of the event to execute.
* @param params [WritableMap] payload of the event
*/
@Synchronized
public fun dispatchUnique(eventName: String, params: WritableMap?) {
if (!isValid) {
return
}
dispatchUniqueEvent(eventName, params as NativeMap?)
}

@Synchronized
public fun destroy() {
if (isValid) {
resetNative()
}
}

private companion object {
init {
staticInit()
}
}
}
Loading