Skip to content

Commit 9a5a679

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Migrate CallbackImpl to Kotlin (facebook#50263)
Summary: Migrate com.facebook.react.bridge.CallbackImpl to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.bridge.CallbackImpl to Kotlin Pull Request resolved: facebook#50263 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71855490 Pulled By: Abbondanzo fbshipit-source-id: 72f15083010601b56f415493d58fc557f3ab35ef
1 parent 2bc0fe6 commit 9a5a679

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.bridge
9+
10+
import com.facebook.react.common.annotations.internal.LegacyArchitecture
11+
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
12+
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
13+
14+
/** Implementation of javascript callback function that uses Bridge to schedule method execution. */
15+
@LegacyArchitecture
16+
public class CallbackImpl(private val jsInstance: JSInstance, private val callbackId: Int) :
17+
Callback {
18+
private var invoked = false
19+
20+
override fun invoke(vararg args: Any?) {
21+
if (invoked) {
22+
throw RuntimeException(
23+
"Illegal callback invocation from native module. This callback type only permits a single invocation from native code.")
24+
}
25+
jsInstance.invokeCallback(callbackId, Arguments.fromJavaArgs(args))
26+
invoked = true
27+
}
28+
29+
private companion object {
30+
init {
31+
LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled(
32+
"CallbackImpl", LegacyArchitectureLogLevel.WARNING)
33+
}
34+
}
35+
}

packages/react-native/ReactAndroid/src/test/java/com/facebook/react/bridge/BaseJavaModuleTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class BaseJavaModuleTest {
3030

3131
@Before
3232
fun setup() {
33+
val jsInstance = mock(JSInstance::class.java)
3334
val moduleHolder = ModuleHolder(MethodsModule())
34-
moduleWrapper = JavaModuleWrapper(null, moduleHolder)
35+
moduleWrapper = JavaModuleWrapper(jsInstance, moduleHolder)
3536
methods = moduleWrapper.methodDescriptors
3637
val generatedModuleHolder = ModuleHolder(GeneratedMethodsModule())
3738
generatedModuleWrapper = JavaModuleWrapper(null, generatedModuleHolder)

0 commit comments

Comments
 (0)