From b6b91f791b424320e5e5834f8ab52dff80085415 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 26 Jul 2024 03:14:36 -0700 Subject: [PATCH] Convert BlackHoleEventDispatcher to Kotlin Summary: # Changelog: [Internal] - As in the title. Differential Revision: D60283138 --- .../ReactAndroid/api/ReactAndroid.api | 9 ++- .../events/BlackHoleEventDispatcher.java | 62 ------------------- .../events/BlackHoleEventDispatcher.kt | 57 +++++++++++++++++ 3 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 8fa2a53b5365d9..3b4af3b7cd29ac 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -5549,12 +5549,13 @@ public abstract interface class com/facebook/react/uimanager/events/BatchEventDi public abstract fun onBatchEventDispatched ()V } -public class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/facebook/react/uimanager/events/EventDispatcher { +public final class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/facebook/react/uimanager/events/EventDispatcher { + public static final field Companion Lcom/facebook/react/uimanager/events/BlackHoleEventDispatcher$Companion; public fun addBatchEventDispatchedListener (Lcom/facebook/react/uimanager/events/BatchEventDispatchedListener;)V public fun addListener (Lcom/facebook/react/uimanager/events/EventDispatcherListener;)V public fun dispatchAllEvents ()V public fun dispatchEvent (Lcom/facebook/react/uimanager/events/Event;)V - public static fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher; + public static final fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher; public fun onCatalystInstanceDestroyed ()V public fun registerEventEmitter (ILcom/facebook/react/uimanager/events/RCTEventEmitter;)V public fun registerEventEmitter (ILcom/facebook/react/uimanager/events/RCTModernEventEmitter;)V @@ -5563,6 +5564,10 @@ public class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/ public fun unregisterEventEmitter (I)V } +public final class com/facebook/react/uimanager/events/BlackHoleEventDispatcher$Companion { + public final fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher; +} + public final class com/facebook/react/uimanager/events/ContentSizeChangeEvent : com/facebook/react/uimanager/events/Event { public fun (III)V public fun (IIII)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.java deleted file mode 100644 index 8b7a36d85b5f71..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.java +++ /dev/null @@ -1,62 +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.uimanager.events; - -import com.facebook.common.logging.FLog; -import com.facebook.infer.annotation.Nullsafe; - -/** - * A singleton class that overrides {@link EventDispatcher} with no-op methods, to be used by - * callers that expect an EventDispatcher when the instance doesn't exist. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class BlackHoleEventDispatcher implements EventDispatcher { - - private static final EventDispatcher sEventDispatcher = new BlackHoleEventDispatcher(); - - public static EventDispatcher get() { - return sEventDispatcher; - } - - private BlackHoleEventDispatcher() {} - - @Override - public void dispatchEvent(Event event) { - FLog.d( - getClass().getSimpleName(), - "Trying to emit event to JS, but the React instance isn't ready. Event: " - + event.getEventName()); - } - - @Override - public void dispatchAllEvents() {} - - @Override - public void addListener(EventDispatcherListener listener) {} - - @Override - public void removeListener(EventDispatcherListener listener) {} - - @Override - public void addBatchEventDispatchedListener(BatchEventDispatchedListener listener) {} - - @Override - public void removeBatchEventDispatchedListener(BatchEventDispatchedListener listener) {} - - @Override - public void registerEventEmitter(int uiManagerType, RCTEventEmitter eventEmitter) {} - - @Override - public void registerEventEmitter(int uiManagerType, RCTModernEventEmitter eventEmitter) {} - - @Override - public void unregisterEventEmitter(int uiManagerType) {} - - @Override - public void onCatalystInstanceDestroyed() {} -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.kt new file mode 100644 index 00000000000000..ccd84d307598a8 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/BlackHoleEventDispatcher.kt @@ -0,0 +1,57 @@ +/* + * 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.common.logging.FLog + +/** + * A singleton class that overrides [EventDispatcher] with no-op methods, to be used by callers that + * expect an EventDispatcher when the instance doesn't exist. + */ +public class BlackHoleEventDispatcher private constructor() : EventDispatcher { + public override fun dispatchEvent(event: Event<*>) { + FLog.d( + javaClass.simpleName, + "Trying to emit event to JS, but the React instance isn't ready. Event: ${event.eventName}") + } + + public override fun dispatchAllEvents(): Unit = Unit + + public override fun addListener(listener: EventDispatcherListener): Unit = Unit + + public override fun removeListener(listener: EventDispatcherListener): Unit = Unit + + public override fun addBatchEventDispatchedListener( + listener: BatchEventDispatchedListener + ): Unit = Unit + + public override fun removeBatchEventDispatchedListener( + listener: BatchEventDispatchedListener + ): Unit = Unit + + @Suppress("DEPRECATION") + public override fun registerEventEmitter( + uiManagerType: Int, + eventEmitter: RCTEventEmitter + ): Unit = Unit + + public override fun registerEventEmitter( + uiManagerType: Int, + eventEmitter: RCTModernEventEmitter + ): Unit = Unit + + public override fun unregisterEventEmitter(uiManagerType: Int): Unit = Unit + + public override fun onCatalystInstanceDestroyed(): Unit = Unit + + public companion object { + private val eventDispatcher: EventDispatcher = BlackHoleEventDispatcher() + + public @JvmStatic fun get(): EventDispatcher = eventDispatcher + } +}