Skip to content

Commit bb6f55e

Browse files
rshestfacebook-github-bot
authored andcommitted
Migrate TurboModuleManagerDelegate to Kotlin (facebook#50727)
Summary: Pull Request resolved: facebook#50727 ## Changelog: [Android] [Internal] - As in the title Reviewed By: cortinico Differential Revision: D73031128 fbshipit-source-id: b61f46d6877e4fda55e87552874aed7a0bee2736
1 parent 0c77bb9 commit bb6f55e

File tree

3 files changed

+64
-78
lines changed

3 files changed

+64
-78
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class TurboModuleManager(
6262

6363
installJSIBindings(shouldEnableLegacyModuleInterop())
6464

65-
eagerInitModuleNames = delegate?.eagerInitModuleNames ?: emptyList()
65+
eagerInitModuleNames = delegate?.getEagerInitModuleNames() ?: emptyList()
6666

6767
val nullProvider: ModuleProvider = ModuleProvider { _: String -> null }
6868

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.java

Lines changed: 0 additions & 77 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.internal.turbomodule.core
9+
10+
import com.facebook.jni.HybridData
11+
import com.facebook.proguard.annotations.DoNotStrip
12+
import com.facebook.react.bridge.NativeModule
13+
import com.facebook.react.turbomodule.core.interfaces.TurboModule
14+
import com.facebook.soloader.SoLoader
15+
16+
public abstract class TurboModuleManagerDelegate {
17+
18+
// NOTE: This *must* be called "mHybridData"
19+
@DoNotStrip @Suppress("unused", "NoHungarianNotation") private val mHybridData: HybridData
20+
21+
protected abstract fun initHybrid(): HybridData
22+
23+
protected constructor() {
24+
maybeLoadOtherSoLibraries()
25+
mHybridData = initHybrid()
26+
}
27+
28+
protected constructor(hybridData: HybridData) {
29+
maybeLoadOtherSoLibraries()
30+
this.mHybridData = hybridData
31+
}
32+
33+
/**
34+
* Create and return a TurboModule Java object with name `moduleName`. If `moduleName` isn't a
35+
* TurboModule, return null.
36+
*/
37+
public abstract fun getModule(moduleName: String?): TurboModule?
38+
39+
public abstract fun unstable_isModuleRegistered(moduleName: String?): Boolean
40+
41+
/**
42+
* Create an return a legacy NativeModule with name `moduleName`. If `moduleName` is a
43+
* TurboModule, return null.
44+
*/
45+
public open fun getLegacyModule(moduleName: String?): NativeModule? = null
46+
47+
public open fun unstable_isLegacyModuleRegistered(moduleName: String?): Boolean = false
48+
49+
public open fun getEagerInitModuleNames(): List<String> = emptyList()
50+
51+
/** Can the TurboModule system create legacy modules? */
52+
public open fun unstable_shouldEnableLegacyModuleInterop(): Boolean = false
53+
54+
// TODO(T171231381): Consider removing this method: could we just use the static initializer
55+
// of derived classes instead?
56+
@Synchronized protected fun maybeLoadOtherSoLibraries(): Unit = Unit
57+
58+
private companion object {
59+
init {
60+
SoLoader.loadLibrary("turbomodulejsijni")
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)