-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert InteropEvent and InteropEventEmitter to Kotlin
Summary: Just converting those two classes to Kotlin as I was going over them. Changelog: [Internal] [Changed] - Convert InteropEvent and InteropEventEmitter to Kotlin Differential Revision: D52869490 fbshipit-source-id: a56d9862208b705df16cfe316a38f97920c7d9d8
- Loading branch information
1 parent
8ac08c8
commit f0837b0
Showing
5 changed files
with
81 additions
and
109 deletions.
There are no files selected for viewing
41 changes: 0 additions & 41 deletions
41
...t-native/ReactAndroid/src/main/java/com/facebook/react/internal/interop/InteropEvent.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...act-native/ReactAndroid/src/main/java/com/facebook/react/internal/interop/InteropEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.internal.interop | ||
|
||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.uimanager.events.Event | ||
|
||
/** | ||
* An [Event] class used by the [InteropEventEmitter]. This class is just holding the | ||
* event name and the data which is received by the `receiveEvent` method and will be passed over | ||
* the the [com.facebook.react.uimanager.events.EventDispatcher] | ||
*/ | ||
class InteropEvent( | ||
@get:JvmName("eventName") val eventName: String, | ||
@get:JvmName("eventName") val eventData: WritableMap?, | ||
surfaceId: Int, | ||
viewTag: Int | ||
) : Event<InteropEvent>(surfaceId, viewTag) { | ||
override fun getEventName(): String = eventName | ||
override fun getEventData(): WritableMap? = eventData | ||
} | ||
|
65 changes: 0 additions & 65 deletions
65
...e/ReactAndroid/src/main/java/com/facebook/react/internal/interop/InteropEventEmitter.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...ive/ReactAndroid/src/main/java/com/facebook/react/internal/interop/InteropEventEmitter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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. | ||
*/ | ||
@file:Suppress("DEPRECATION") // We want to use RCTEventEmitter for interop purposes | ||
package com.facebook.react.internal.interop | ||
|
||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.bridge.WritableArray | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.common.annotations.VisibleForTesting | ||
import com.facebook.react.uimanager.UIManagerHelper | ||
import com.facebook.react.uimanager.events.EventDispatcher | ||
import com.facebook.react.uimanager.events.RCTEventEmitter | ||
|
||
/** | ||
* A reimplementation of [RCTEventEmitter] which is using a [EventDispatcher] under the | ||
* hood. | ||
* | ||
* On Fabric, you're supposed to use [EventDispatcher] to dispatch events. However, we | ||
* provide an interop layer for non-Fabric migrated components. | ||
* | ||
* This instance will be returned if the user is invoking `context.getJsModule(RCTEventEmitter) | ||
* and is providing support for the `receiveEvent` method, so that non-Fabric ViewManagers can | ||
* continue to deliver events also when Fabric is turned on. | ||
*/ | ||
class InteropEventEmitter(private val reactContext: ReactContext) : RCTEventEmitter { | ||
private var eventDispatcherOverride: EventDispatcher? = null | ||
|
||
@Deprecated("Deprecated in Java") | ||
override fun receiveEvent(targetReactTag: Int, eventName: String, eventData: WritableMap?) { | ||
val dispatcher: EventDispatcher? = eventDispatcherOverride ?: UIManagerHelper.getEventDispatcherForReactTag(reactContext, targetReactTag) | ||
val surfaceId = UIManagerHelper.getSurfaceId(reactContext) | ||
dispatcher?.dispatchEvent(InteropEvent(eventName, eventData, surfaceId, targetReactTag)) | ||
} | ||
|
||
override fun receiveTouches( | ||
eventName: String, touches: WritableArray, changedIndices: WritableArray) { | ||
throw UnsupportedOperationException( | ||
"EventEmitter#receiveTouches is not supported by the Fabric Interop Layer") | ||
} | ||
|
||
@VisibleForTesting | ||
fun overrideEventDispatcher(eventDispatcherOverride: EventDispatcher?) { | ||
this.eventDispatcherOverride = eventDispatcherOverride | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters