From 9f52378cc1061c7c9dae6aee5147bb54f0aa24aa Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Sat, 16 Sep 2023 01:35:01 -0700 Subject: [PATCH] deprecate hasConstants from ReactModuleInfo (#39459) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39459 ## Changelog [Android][Deprecated] - ReactModuleInfo constructor with getConstants arg is deprecated introducing a new constructor that doesn't use getConstants and updating the internal codebase to use it. deprecated the old one since it's been copypasta'd a lot in oss. Reviewed By: cortinico Differential Revision: D49262824 fbshipit-source-id: 1a4d36b3153d8ce0ee869b8635c94005fe7c9594 --- .../react/tests/core/ReactRootViewTest.java | 1 - .../com/facebook/react/CoreModulesPackage.java | 1 - .../com/facebook/react/DebugCorePackage.java | 1 - .../ReactPackageTurboModuleManagerDelegate.java | 2 -- .../com/facebook/react/bridge/ModuleHolder.java | 1 - .../react/module/model/ReactModuleInfo.java | 17 ++++++++++++++++- .../processing/ReactModuleSpecProcessor.java | 2 -- .../react/runtime/CoreReactPackage.java | 1 - .../facebook/react/shell/MainReactPackage.java | 3 --- .../react/uiapp/RNTesterApplication.java | 2 -- .../react/uiapp/RNTesterReactHostDelegate.kt | 2 -- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/ReactRootViewTest.java b/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/ReactRootViewTest.java index bf23d9e66cb9e4..64e59f2a588525 100644 --- a/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/ReactRootViewTest.java +++ b/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/ReactRootViewTest.java @@ -79,7 +79,6 @@ public Map getReactModuleInfos() { moduleClass.getName(), reactModule.canOverrideExistingModule(), reactModule.needsEagerInit(), - reactModule.hasConstants(), reactModule.isCxxModule(), false)); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index 5883ee1b17e40a..5b3e5bb3c31349 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -114,7 +114,6 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { moduleClass.getName(), reactModule.canOverrideExistingModule(), reactModule.needsEagerInit(), - reactModule.hasConstants(), reactModule.isCxxModule(), TurboModule.class.isAssignableFrom(moduleClass))); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java index c6778bc24b4fdb..cc98ffd79b1874 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java @@ -73,7 +73,6 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { moduleClass.getName(), reactModule.canOverrideExistingModule(), reactModule.needsEagerInit(), - reactModule.hasConstants(), reactModule.isCxxModule(), TurboModule.class.isAssignableFrom(moduleClass))); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactPackageTurboModuleManagerDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactPackageTurboModuleManagerDelegate.java index 570f3b7312b70d..905f016c0ef553 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactPackageTurboModuleManagerDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactPackageTurboModuleManagerDelegate.java @@ -108,7 +108,6 @@ protected ReactPackageTurboModuleManagerDelegate( moduleClass.getName(), reactModule.canOverrideExistingModule(), true, - reactModule.hasConstants(), reactModule.isCxxModule(), TurboModule.class.isAssignableFrom(moduleClass)) : new ReactModuleInfo( @@ -116,7 +115,6 @@ protected ReactPackageTurboModuleManagerDelegate( moduleClass.getName(), module.canOverrideExistingModule(), true, - true, CxxModuleWrapper.class.isAssignableFrom(moduleClass), TurboModule.class.isAssignableFrom(moduleClass)); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ModuleHolder.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ModuleHolder.java index 9837f1fe010425..24e14e34000b3c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ModuleHolder.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ModuleHolder.java @@ -71,7 +71,6 @@ public ModuleHolder(NativeModule nativeModule) { nativeModule.getClass().getSimpleName(), nativeModule.canOverrideExistingModule(), true, - true, CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass()), TurboModule.class.isAssignableFrom(nativeModule.getClass())); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java index ef6a13fa5465a5..ae4a56bbc3a969 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java @@ -25,7 +25,6 @@ public ReactModuleInfo( String className, boolean canOverrideExistingModule, boolean needsEagerInit, - boolean hasConstants, boolean isCxxModule, boolean isTurboModule) { mName = name; @@ -36,6 +35,22 @@ public ReactModuleInfo( mIsTurboModule = isTurboModule; } + /** + * @deprecated use {@link ReactModuleInfo#ReactModuleInfo(String, String, boolean, boolean, + * boolean, boolean)} + */ + @Deprecated + public ReactModuleInfo( + String name, + String className, + boolean canOverrideExistingModule, + boolean needsEagerInit, + boolean hasConstants, + boolean isCxxModule, + boolean isTurboModule) { + this(name, className, canOverrideExistingModule, needsEagerInit, isCxxModule, isTurboModule); + } + public String name() { return mName; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java index 039661274968e2..44d73c2ad4e8aa 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java @@ -228,8 +228,6 @@ private CodeBlock getCodeBlockForReactModuleInfos(List nativeModules) .append(", ") .append(reactModule.needsEagerInit()) .append(", ") - .append(hasConstants) - .append(", ") .append(reactModule.isCxxModule()) .append(", ") .append(isTurboModule) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/CoreReactPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/CoreReactPackage.java index f82769ce8b23d6..5ed3e4aa8d1129 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/CoreReactPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/CoreReactPackage.java @@ -97,7 +97,6 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { moduleClass.getName(), reactModule.canOverrideExistingModule(), reactModule.needsEagerInit(), - reactModule.hasConstants(), reactModule.isCxxModule(), TurboModule.class.isAssignableFrom(moduleClass))); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index a686584f6ee087..860fb362be4c48 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -283,7 +283,6 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { final Map reactModuleInfoMap = new HashMap<>(); for (Class moduleClass : moduleList) { ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); - if (reactModule != null) { reactModuleInfoMap.put( reactModule.name(), @@ -292,12 +291,10 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { moduleClass.getName(), reactModule.canOverrideExistingModule(), reactModule.needsEagerInit(), - reactModule.hasConstants(), reactModule.isCxxModule(), TurboModule.class.isAssignableFrom(moduleClass))); } } - return () -> reactModuleInfoMap; } catch (InstantiationException e) { throw new RuntimeException( diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java index 0706214a22f662..5d4bf72b037440 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -102,7 +102,6 @@ public Map getReactModuleInfos() { "SampleTurboModule", false, // canOverrideExistingModule false, // needsEagerInit - true, // hasConstants false, // isCxxModule true // isTurboModule )); @@ -114,7 +113,6 @@ public Map getReactModuleInfos() { "SampleLegacyModule", false, // canOverrideExistingModule false, // needsEagerInit - true, // hasConstants false, // isCxxModule false // isTurboModule )); diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.kt b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.kt index 0b9895b4ea4e82..aa0111fec1328f 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.kt +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.kt @@ -90,7 +90,6 @@ class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHo "SampleTurboModule", false, // canOverrideExistingModule false, // needsEagerInit - true, // hasConstants false, // isCxxModule true // isTurboModule ), @@ -100,7 +99,6 @@ class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHo "SampleLegacyModule", false, // canOverrideExistingModule false, // needsEagerInit - true, // hasConstants false, // isCxxModule false // isTurboModule ),