mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Convert CoreReactPackage.java to Kotlin (#50709)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50709 Convert Java to Kotlin Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D72825456 fbshipit-source-id: 4c71ae9892c217a722a74d662f6ae1ca68b97d3f
This commit is contained in:
1 parent
c9bee009c3
commit
a13f84adcc
9 files changed
+159
-143
No files matched your search
@@ -2712,6 +2712,8 @@ public abstract interface class com/facebook/react/modules/core/DeviceEventManag
|
||||
}
|
||||
|
||||
public class com/facebook/react/modules/core/ExceptionsManagerModule : com/facebook/fbreact/specs/NativeExceptionsManagerSpec {
|
||||
public static final field Companion Lcom/facebook/react/modules/core/ExceptionsManagerModule$Companion;
|
||||
public static final field NAME Ljava/lang/String;
|
||||
public fun <init> (Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
|
||||
public fun dismissRedbox ()V
|
||||
public fun reportException (Lcom/facebook/react/bridge/ReadableMap;)V
|
||||
@@ -2719,6 +2721,9 @@ public class com/facebook/react/modules/core/ExceptionsManagerModule : com/faceb
|
||||
public fun reportSoftException (Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;D)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/core/ExceptionsManagerModule$Companion {
|
||||
}
|
||||
|
||||
public class com/facebook/react/modules/core/HeadlessJsTaskSupportModule : com/facebook/fbreact/specs/NativeHeadlessJsTaskSupportSpec {
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
|
||||
public fun notifyTaskFinished (D)V
|
||||
@@ -2802,6 +2807,8 @@ public final class com/facebook/react/modules/core/TimingModule$Companion {
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/debug/DevSettingsModule : com/facebook/fbreact/specs/NativeDevSettingsSpec {
|
||||
public static final field Companion Lcom/facebook/react/modules/debug/DevSettingsModule$Companion;
|
||||
public static final field NAME Ljava/lang/String;
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
|
||||
public fun addListener (Ljava/lang/String;)V
|
||||
public fun addMenuItem (Ljava/lang/String;)V
|
||||
@@ -2816,6 +2823,9 @@ public final class com/facebook/react/modules/debug/DevSettingsModule : com/face
|
||||
public fun toggleElementInspector ()V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/debug/DevSettingsModule$Companion {
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/debug/FpsDebugFrameCallback : android/view/Choreographer$FrameCallback {
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
|
||||
public fun doFrame (J)V
|
||||
@@ -2847,9 +2857,14 @@ public final class com/facebook/react/modules/debug/FpsDebugFrameCallback$FpsInf
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/debug/SourceCodeModule : com/facebook/fbreact/specs/NativeSourceCodeSpec {
|
||||
public static final field Companion Lcom/facebook/react/modules/debug/SourceCodeModule$Companion;
|
||||
public static final field NAME Ljava/lang/String;
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/debug/SourceCodeModule$Companion {
|
||||
}
|
||||
|
||||
public abstract interface class com/facebook/react/modules/debug/interfaces/DeveloperSettings {
|
||||
public abstract fun addMenuItem (Ljava/lang/String;)V
|
||||
public abstract fun getPackagerConnectionSettings ()Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;
|
||||
@@ -3144,11 +3159,16 @@ public final class com/facebook/react/modules/systeminfo/AndroidInfoHelpers {
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/systeminfo/AndroidInfoModule : com/facebook/fbreact/specs/NativePlatformConstantsAndroidSpec {
|
||||
public static final field Companion Lcom/facebook/react/modules/systeminfo/AndroidInfoModule$Companion;
|
||||
public static final field NAME Ljava/lang/String;
|
||||
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
|
||||
public fun getAndroidID ()Ljava/lang/String;
|
||||
public fun invalidate ()V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/systeminfo/AndroidInfoModule$Companion {
|
||||
}
|
||||
|
||||
public final class com/facebook/react/modules/systeminfo/ReactNativeVersion {
|
||||
public static final field INSTANCE Lcom/facebook/react/modules/systeminfo/ReactNativeVersion;
|
||||
public static final field VERSION Ljava/util/Map;
|
||||
|
||||
+4
@@ -65,4 +65,8 @@ public open class ExceptionsManagerModule(private val devSupportManager: DevSupp
|
||||
devSupportManager.hideRedboxDialog()
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = NativeExceptionsManagerSpec.NAME
|
||||
}
|
||||
}
|
||||
+4
@@ -39,4 +39,8 @@ internal class DevMenuModule(
|
||||
override fun setHotLoadingEnabled(enabled: Boolean) {
|
||||
devSupportManager.setHotModuleReplacementEnabled(enabled)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = NativeDevMenuSpec.NAME
|
||||
}
|
||||
}
|
||||
+4
@@ -72,4 +72,8 @@ public class DevSettingsModule(
|
||||
override fun removeListeners(count: Double) {
|
||||
// iOS only
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = NativeDevSettingsSpec.NAME
|
||||
}
|
||||
}
|
||||
+4
@@ -24,4 +24,8 @@ public class SourceCodeModule(reactContext: ReactApplicationContext) :
|
||||
Assertions.assertNotNull<String>(
|
||||
getReactApplicationContext().getSourceURL(),
|
||||
"No source URL loaded, have you initialised the instance?"))
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = NativeSourceCodeSpec.NAME
|
||||
}
|
||||
}
|
||||
+4
@@ -73,4 +73,8 @@ internal class DeviceInfoModule(reactContext: ReactApplicationContext) :
|
||||
super.invalidate()
|
||||
reactApplicationContext?.removeLifecycleEventListener(this)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = NativeDeviceInfoSpec.NAME
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -25,11 +25,6 @@ import com.facebook.react.module.annotations.ReactModule
|
||||
public class AndroidInfoModule(reactContext: ReactApplicationContext) :
|
||||
NativePlatformConstantsAndroidSpec(reactContext) {
|
||||
|
||||
private companion object {
|
||||
private const val IS_TESTING = "IS_TESTING"
|
||||
private const val IS_DISABLE_ANIMATIONS = "IS_DISABLE_ANIMATIONS"
|
||||
}
|
||||
|
||||
/**
|
||||
* See:
|
||||
* https://developer.android.com/reference/android/app/UiModeManager.html#getCurrentModeType()
|
||||
@@ -84,4 +79,10 @@ public class AndroidInfoModule(reactContext: ReactApplicationContext) :
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public const val NAME: String = "NativePlatformConstantsAndroidSpec.NAME"
|
||||
private const val IS_TESTING = "IS_TESTING"
|
||||
private const val IS_DISABLE_ANIMATIONS = "IS_DISABLE_ANIMATIONS"
|
||||
}
|
||||
}
|
||||
-138
@@ -1,138 +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.runtime;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.BaseReactPackage;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.common.ClassFinder;
|
||||
import com.facebook.react.devsupport.LogBoxModule;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.module.annotations.ReactModuleList;
|
||||
import com.facebook.react.module.model.ReactModuleInfo;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.core.ExceptionsManagerModule;
|
||||
import com.facebook.react.modules.debug.DevMenuModule;
|
||||
import com.facebook.react.modules.debug.DevSettingsModule;
|
||||
import com.facebook.react.modules.debug.SourceCodeModule;
|
||||
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
|
||||
import com.facebook.react.modules.systeminfo.AndroidInfoModule;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
@ReactModuleList(
|
||||
nativeModules = {
|
||||
AndroidInfoModule.class,
|
||||
DeviceInfoModule.class,
|
||||
DevMenuModule.class,
|
||||
DevSettingsModule.class,
|
||||
SourceCodeModule.class,
|
||||
LogBoxModule.class,
|
||||
DeviceEventManagerModule.class,
|
||||
ExceptionsManagerModule.class,
|
||||
})
|
||||
class CoreReactPackage extends BaseReactPackage {
|
||||
|
||||
private final DevSupportManager mDevSupportManager;
|
||||
private final DefaultHardwareBackBtnHandler mHardwareBackBtnHandler;
|
||||
|
||||
public CoreReactPackage(
|
||||
DevSupportManager devSupportManager, DefaultHardwareBackBtnHandler hardwareBackBtnHandler) {
|
||||
mDevSupportManager = devSupportManager;
|
||||
mHardwareBackBtnHandler = hardwareBackBtnHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
||||
switch (name) {
|
||||
case AndroidInfoModule.NAME:
|
||||
return new AndroidInfoModule(reactContext);
|
||||
case DeviceInfoModule.NAME:
|
||||
return new DeviceInfoModule(reactContext);
|
||||
case SourceCodeModule.NAME:
|
||||
return new SourceCodeModule(reactContext);
|
||||
case DevMenuModule.NAME:
|
||||
return new DevMenuModule(reactContext, mDevSupportManager);
|
||||
case DevSettingsModule.NAME:
|
||||
return new DevSettingsModule(reactContext, mDevSupportManager);
|
||||
case DeviceEventManagerModule.NAME:
|
||||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
|
||||
case LogBoxModule.NAME:
|
||||
return new LogBoxModule(reactContext, mDevSupportManager);
|
||||
case ExceptionsManagerModule.NAME:
|
||||
return new ExceptionsManagerModule(mDevSupportManager);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
||||
if (!ClassFinder.canLoadClassesFromAnnotationProcessors()) {
|
||||
return fallbackForMissingClass();
|
||||
}
|
||||
try {
|
||||
Class<?> reactModuleInfoProviderClass =
|
||||
ClassFinder.findClass(CoreReactPackage.class.getName() + "$$ReactModuleInfoProvider");
|
||||
return (ReactModuleInfoProvider)
|
||||
Assertions.assertNotNull(reactModuleInfoProviderClass).newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return fallbackForMissingClass();
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(
|
||||
"No ReactModuleInfoProvider for "
|
||||
+ CoreReactPackage.class.getName()
|
||||
+ "$$ReactModuleInfoProvider",
|
||||
e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(
|
||||
"No ReactModuleInfoProvider for "
|
||||
+ CoreReactPackage.class.getName()
|
||||
+ "$$ReactModuleInfoProvider",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
private ReactModuleInfoProvider fallbackForMissingClass() {
|
||||
// In OSS case, the annotation processor does not run. We fall back on creating this byhand
|
||||
Class<? extends NativeModule>[] moduleList =
|
||||
new Class[] {
|
||||
AndroidInfoModule.class,
|
||||
DeviceInfoModule.class,
|
||||
SourceCodeModule.class,
|
||||
DevMenuModule.class,
|
||||
DevSettingsModule.class,
|
||||
DeviceEventManagerModule.class,
|
||||
LogBoxModule.class,
|
||||
ExceptionsManagerModule.class,
|
||||
};
|
||||
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>();
|
||||
for (Class<? extends NativeModule> moduleClass : moduleList) {
|
||||
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class);
|
||||
if (reactModule != null) {
|
||||
reactModuleInfoMap.put(
|
||||
reactModule.name(),
|
||||
new ReactModuleInfo(
|
||||
reactModule.name(),
|
||||
moduleClass.getName(),
|
||||
reactModule.canOverrideExistingModule(),
|
||||
reactModule.needsEagerInit(),
|
||||
reactModule.isCxxModule(),
|
||||
ReactModuleInfo.classIsTurboModule(moduleClass)));
|
||||
}
|
||||
}
|
||||
return () -> reactModuleInfoMap;
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.runtime
|
||||
|
||||
import com.facebook.react.BaseReactPackage
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.common.ClassFinder
|
||||
import com.facebook.react.devsupport.LogBoxModule
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager
|
||||
import com.facebook.react.module.annotations.ReactModule
|
||||
import com.facebook.react.module.annotations.ReactModuleList
|
||||
import com.facebook.react.module.model.ReactModuleInfo
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule
|
||||
import com.facebook.react.modules.core.ExceptionsManagerModule
|
||||
import com.facebook.react.modules.debug.DevMenuModule
|
||||
import com.facebook.react.modules.debug.DevSettingsModule
|
||||
import com.facebook.react.modules.debug.SourceCodeModule
|
||||
import com.facebook.react.modules.deviceinfo.DeviceInfoModule
|
||||
import com.facebook.react.modules.systeminfo.AndroidInfoModule
|
||||
import java.util.HashMap
|
||||
|
||||
@ReactModuleList(
|
||||
nativeModules =
|
||||
[
|
||||
AndroidInfoModule::class,
|
||||
DeviceInfoModule::class,
|
||||
DevMenuModule::class,
|
||||
DevSettingsModule::class,
|
||||
SourceCodeModule::class,
|
||||
LogBoxModule::class,
|
||||
DeviceEventManagerModule::class,
|
||||
ExceptionsManagerModule::class])
|
||||
internal class CoreReactPackage(
|
||||
private val devSupportManager: DevSupportManager,
|
||||
private val hardwareBackBtnHandler: DefaultHardwareBackBtnHandler
|
||||
) : BaseReactPackage() {
|
||||
|
||||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
||||
when (name) {
|
||||
AndroidInfoModule.NAME -> AndroidInfoModule(reactContext)
|
||||
DeviceInfoModule.NAME -> DeviceInfoModule(reactContext)
|
||||
SourceCodeModule.NAME -> SourceCodeModule(reactContext)
|
||||
DevMenuModule.NAME -> DevMenuModule(reactContext, devSupportManager)
|
||||
DevSettingsModule.NAME -> DevSettingsModule(reactContext, devSupportManager)
|
||||
DeviceEventManagerModule.NAME ->
|
||||
DeviceEventManagerModule(reactContext, hardwareBackBtnHandler)
|
||||
|
||||
LogBoxModule.NAME -> LogBoxModule(reactContext, devSupportManager)
|
||||
ExceptionsManagerModule.NAME -> ExceptionsManagerModule(devSupportManager)
|
||||
else -> null
|
||||
}
|
||||
|
||||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
||||
if (!ClassFinder.canLoadClassesFromAnnotationProcessors()) {
|
||||
return fallbackForMissingClass()
|
||||
}
|
||||
try {
|
||||
val reactModuleInfoProviderClass =
|
||||
ClassFinder.findClass("${CoreReactPackage::class.java.name}$\$ReactModuleInfoProvider")
|
||||
@Suppress("DEPRECATION")
|
||||
return reactModuleInfoProviderClass?.newInstance() as? ReactModuleInfoProvider
|
||||
?: fallbackForMissingClass()
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is ClassNotFoundException -> return fallbackForMissingClass()
|
||||
is InstantiationException,
|
||||
is IllegalAccessException ->
|
||||
throw RuntimeException(
|
||||
"No ReactModuleInfoProvider for ${CoreReactPackage::class.java.name}$\$ReactModuleInfoProvider",
|
||||
e)
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun fallbackForMissingClass(): ReactModuleInfoProvider {
|
||||
// In OSS case, the annotation processor does not run. We fall back on creating this byhand
|
||||
val moduleList: Array<Class<out NativeModule>> =
|
||||
arrayOf<Class<out NativeModule>>(
|
||||
AndroidInfoModule::class.java,
|
||||
DeviceInfoModule::class.java,
|
||||
SourceCodeModule::class.java,
|
||||
DevMenuModule::class.java,
|
||||
DevSettingsModule::class.java,
|
||||
DeviceEventManagerModule::class.java,
|
||||
LogBoxModule::class.java,
|
||||
ExceptionsManagerModule::class.java,
|
||||
)
|
||||
val reactModuleInfoMap: MutableMap<String, ReactModuleInfo> = HashMap()
|
||||
for (moduleClass in moduleList) {
|
||||
val reactModule = moduleClass.getAnnotation(ReactModule::class.java)
|
||||
if (reactModule != null) {
|
||||
reactModuleInfoMap[reactModule.name] =
|
||||
ReactModuleInfo(
|
||||
reactModule.name,
|
||||
moduleClass.name,
|
||||
reactModule.canOverrideExistingModule,
|
||||
reactModule.needsEagerInit,
|
||||
reactModule.isCxxModule,
|
||||
ReactModuleInfo.classIsTurboModule(moduleClass))
|
||||
}
|
||||
}
|
||||
return ReactModuleInfoProvider { reactModuleInfoMap }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user