Skip to content

Commit 36e5f41

Browse files
cortinicofacebook-github-bot
authored andcommitted
@DeprecatedInNewArchitecture -> @deprecated (#52399)
Summary: I'm raising the deprecation warnings for those methods that are using legacy arch. Previously the `DeprecatedInNewArchitecture` was not generating warnings for user in their builds, while now the Kotlin's/Java's `DeprecatedInNewArchitecture` it will. Changelog: [Android] [Changed] - Introduce more deprecation warnings for Legacy Arch classes Reviewed By: mdvacca Differential Revision: D77736713
1 parent 4e62558 commit 36e5f41

File tree

24 files changed

+58
-49
lines changed

24 files changed

+58
-49
lines changed

packages/react-native-test-library/android/src/main/java/com/facebook/react/osslibraryexample/OSSLibraryExamplePackage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import com.facebook.react.bridge.NativeModule
1212
import com.facebook.react.bridge.ReactApplicationContext
1313
import com.facebook.react.uimanager.ViewManager
1414

15+
@Suppress("DEPRECATION")
1516
public class OSSLibraryExamplePackage : ReactPackage {
17+
@Deprecated("Migrate to [BaseReactPackage] and implement [getModule] instead.")
1618
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
1719
listOf(NativeSampleModule(reactContext))
1820

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public abstract class com/facebook/react/ReactNativeHost {
353353
}
354354

355355
public abstract interface class com/facebook/react/ReactPackage {
356-
public abstract fun createNativeModules (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/List;
356+
public fun createNativeModules (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/List;
357357
public abstract fun createViewManagers (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/List;
358358
public fun getModule (Ljava/lang/String;Lcom/facebook/react/bridge/ReactApplicationContext;)Lcom/facebook/react/bridge/NativeModule;
359359
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/BaseReactPackage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import javax.inject.Provider
2222
/** Abstract class that supports lazy loading of NativeModules by default. */
2323
public abstract class BaseReactPackage : ReactPackage {
2424

25+
@Deprecated("Migrate to [BaseReactPackage] and implement [getModule] instead.")
2526
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
2627
throw UnsupportedOperationException(
2728
"createNativeModules method is not supported. Use getModule() method instead.")

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public abstract class HeadlessJsTaskService : Service(), HeadlessJsTaskEventList
112112
* simply have a different mechanism for storing a `ReactNativeHost`, e.g. as a static field
113113
* somewhere.
114114
*/
115+
@Suppress("DEPRECATION")
115116
protected val reactNativeHost: ReactNativeHost
116117
get() = (application as ReactApplication).reactNativeHost
117118

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public abstract class LazyReactPackage : ReactPackage {
9292
* @param reactContext react application context that can be used to create modules
9393
* @return A [List]<[NativeModule]> to register
9494
*/
95+
@Suppress("DEPRECATION")
96+
@Deprecated("Migrate to [BaseReactPackage] and implement [getModule] instead.")
9597
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
9698
buildList {
9799
for (holder in getNativeModules(reactContext)) {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.facebook.infer.annotation.Assertions;
2121
import com.facebook.react.bridge.Callback;
2222
import com.facebook.react.bridge.ReactContext;
23-
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture;
2423
import com.facebook.react.interfaces.fabric.ReactSurface;
2524
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
2625
import com.facebook.react.modules.core.PermissionListener;
@@ -86,8 +85,11 @@ public ReactActivityDelegate(
8685
* ReactApplication#getReactNativeHost()}. Override this method if your application class does not
8786
* implement {@code ReactApplication} or you simply have a different mechanism for storing a
8887
* {@code ReactNativeHost}, e.g. as a static field somewhere.
88+
*
89+
* @deprecated "Do not access {@link ReactNativeHost} directly. This class is going away in the
90+
* New Architecture. You should access {@link ReactHost} instead."
8991
*/
90-
@DeprecatedInNewArchitecture(message = "Use getReactHost()")
92+
@Deprecated
9193
protected ReactNativeHost getReactNativeHost() {
9294
return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost();
9395
}
@@ -107,7 +109,10 @@ protected ReactNativeHost getReactNativeHost() {
107109
return mReactDelegate;
108110
}
109111

110-
@DeprecatedInNewArchitecture(message = "Use getReactHost()")
112+
/**
113+
* @deprecated @deprecated "Do not access {@link ReactInstanceManager} directly. This class is
114+
* going away in the New Architecture. You should access {@link ReactHost} instead."
115+
*/
111116
public ReactInstanceManager getReactInstanceManager() {
112117
return mReactDelegate.getReactInstanceManager();
113118
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ package com.facebook.react
1010
/** Interface that represents an instance of a React Native application */
1111
public interface ReactApplication {
1212
/** Get the default [ReactNativeHost] for this app. */
13+
@Suppress("DEPRECATION")
14+
@Deprecated(
15+
"You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
16+
ReplaceWith("reactHost"))
1317
public val reactNativeHost: ReactNativeHost
1418

1519
/**

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import android.os.Bundle
1414
import android.view.KeyEvent
1515
import com.facebook.react.bridge.ReactContext
1616
import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
17-
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture
1817
import com.facebook.react.devsupport.DoubleTapReloadRecognizer
1918
import com.facebook.react.devsupport.ReleaseDevSupportManager
2019
import com.facebook.react.devsupport.interfaces.DevSupportManager
@@ -26,12 +25,17 @@ import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
2625
* A delegate for handling React Application support. This delegate is unaware whether it is used in
2726
* an [Activity] or a [android.app.Fragment].
2827
*/
28+
@Suppress("DEPRECATION")
2929
public open class ReactDelegate {
3030
private val activity: Activity
3131
private var internalReactRootView: ReactRootView? = null
3232
private val mainComponentName: String?
3333
private var launchOptions: Bundle?
3434
private var doubleTapReloadRecognizer: DoubleTapReloadRecognizer?
35+
36+
@Deprecated(
37+
"You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
38+
ReplaceWith("reactHost"))
3539
private var reactNativeHost: ReactNativeHost? = null
3640
public var reactHost: ReactHost? = null
3741
private set
@@ -380,7 +384,8 @@ public open class ReactDelegate {
380384
return false
381385
}
382386

383-
@DeprecatedInNewArchitecture(message = "Use reactHost")
387+
@Deprecated(
388+
"Do not access [ReactInstanceManager] directly. This class is going away in the New Architecture. You should use [ReactHost] instead.")
384389
public fun getReactInstanceManager(): ReactInstanceManager {
385390
val nonNullReactNativeHost =
386391
checkNotNull(reactNativeHost) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactFragment.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public open class ReactFragment : Fragment(), PermissionAwareActivity {
5858
* method if your application class does not implement `ReactApplication` or you simply have a
5959
* different mechanism for storing a `ReactNativeHost`, e.g. as a static field somewhere.
6060
*/
61+
@Suppress("DEPRECATION")
62+
@Deprecated(
63+
"You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
64+
ReplaceWith("reactHost"))
6165
protected open val reactNativeHost: ReactNativeHost?
6266
get() = (activity?.application as ReactApplication?)?.reactNativeHost
6367

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.facebook.react.common.LifecycleState;
1919
import com.facebook.react.common.SurfaceDelegate;
2020
import com.facebook.react.common.SurfaceDelegateFactory;
21-
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture;
2221
import com.facebook.react.common.annotations.internal.LegacyArchitecture;
2322
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel;
2423
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
@@ -32,11 +31,10 @@
3231
/**
3332
* Simple class that holds an instance of {@link ReactInstanceManager}. This can be used in your
3433
* {@link Application class} (see {@link ReactApplication}), or as a static field.
34+
*
35+
* @deprecated This class will be replaced by com.facebook.react.ReactHost in the New Architecture.
3536
*/
36-
@DeprecatedInNewArchitecture(
37-
message =
38-
"This class will be replaced by com.facebook.react.ReactHost in the new architecture of"
39-
+ " React Native.")
37+
@Deprecated
4038
@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR)
4139
public abstract class ReactNativeHost {
4240

0 commit comments

Comments
 (0)