mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate TurboModuleManagerDelegate to Kotlin (#50727)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50727 ## Changelog: [Android] [Internal] - As in the title Reviewed By: cortinico Differential Revision: D73031128 fbshipit-source-id: b61f46d6877e4fda55e87552874aed7a0bee2736
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0c77bb9f58
commit
bb6f55e774
+1
-1
@@ -62,7 +62,7 @@ public class TurboModuleManager(
|
||||
|
||||
installJSIBindings(shouldEnableLegacyModuleInterop())
|
||||
|
||||
eagerInitModuleNames = delegate?.eagerInitModuleNames ?: emptyList()
|
||||
eagerInitModuleNames = delegate?.getEagerInitModuleNames() ?: emptyList()
|
||||
|
||||
val nullProvider: ModuleProvider = ModuleProvider { _: String -> null }
|
||||
|
||||
|
||||
-77
@@ -1,77 +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.internal.turbomodule.core;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public abstract class TurboModuleManagerDelegate {
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
private final HybridData mHybridData;
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("turbomodulejsijni");
|
||||
}
|
||||
|
||||
protected abstract HybridData initHybrid();
|
||||
|
||||
protected TurboModuleManagerDelegate() {
|
||||
maybeLoadOtherSoLibraries();
|
||||
mHybridData = initHybrid();
|
||||
}
|
||||
|
||||
protected TurboModuleManagerDelegate(HybridData hybridData) {
|
||||
maybeLoadOtherSoLibraries();
|
||||
mHybridData = hybridData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a TurboModule Java object with name `moduleName`. If `moduleName` isn't a
|
||||
* TurboModule, return null.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract TurboModule getModule(String moduleName);
|
||||
|
||||
public abstract boolean unstable_isModuleRegistered(String moduleName);
|
||||
|
||||
/**
|
||||
* Create an return a legacy NativeModule with name `moduleName`. If `moduleName` is a
|
||||
* TurboModule, return null.
|
||||
*/
|
||||
@Nullable
|
||||
public NativeModule getLegacyModule(String moduleName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean unstable_isLegacyModuleRegistered(String moduleName) {
|
||||
return false;
|
||||
}
|
||||
;
|
||||
|
||||
public List<String> getEagerInitModuleNames() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/** Can the TurboModule system create legacy modules? */
|
||||
public boolean unstable_shouldEnableLegacyModuleInterop() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(T171231381): Consider removing this method: could we just use the static initializer
|
||||
// of derived classes instead?
|
||||
protected synchronized void maybeLoadOtherSoLibraries() {}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.turbomodule.core
|
||||
|
||||
import com.facebook.jni.HybridData
|
||||
import com.facebook.proguard.annotations.DoNotStrip
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule
|
||||
import com.facebook.soloader.SoLoader
|
||||
|
||||
public abstract class TurboModuleManagerDelegate {
|
||||
|
||||
// NOTE: This *must* be called "mHybridData"
|
||||
@DoNotStrip @Suppress("unused", "NoHungarianNotation") private val mHybridData: HybridData
|
||||
|
||||
protected abstract fun initHybrid(): HybridData
|
||||
|
||||
protected constructor() {
|
||||
maybeLoadOtherSoLibraries()
|
||||
mHybridData = initHybrid()
|
||||
}
|
||||
|
||||
protected constructor(hybridData: HybridData) {
|
||||
maybeLoadOtherSoLibraries()
|
||||
this.mHybridData = hybridData
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a TurboModule Java object with name `moduleName`. If `moduleName` isn't a
|
||||
* TurboModule, return null.
|
||||
*/
|
||||
public abstract fun getModule(moduleName: String?): TurboModule?
|
||||
|
||||
public abstract fun unstable_isModuleRegistered(moduleName: String?): Boolean
|
||||
|
||||
/**
|
||||
* Create an return a legacy NativeModule with name `moduleName`. If `moduleName` is a
|
||||
* TurboModule, return null.
|
||||
*/
|
||||
public open fun getLegacyModule(moduleName: String?): NativeModule? = null
|
||||
|
||||
public open fun unstable_isLegacyModuleRegistered(moduleName: String?): Boolean = false
|
||||
|
||||
public open fun getEagerInitModuleNames(): List<String> = emptyList()
|
||||
|
||||
/** Can the TurboModule system create legacy modules? */
|
||||
public open fun unstable_shouldEnableLegacyModuleInterop(): Boolean = false
|
||||
|
||||
// TODO(T171231381): Consider removing this method: could we just use the static initializer
|
||||
// of derived classes instead?
|
||||
@Synchronized protected fun maybeLoadOtherSoLibraries(): Unit = Unit
|
||||
|
||||
private companion object {
|
||||
init {
|
||||
SoLoader.loadLibrary("turbomodulejsijni")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user