Add missing ReplaceWith on deprecations (#51144)

Summary:
Static code analysis detected several missing `ReplaceWith` on deprecated methods. This diff addresses some of them by adding the most accurate suggestions based on the implementations.

## Changelog:

[INTERNAL] - Add missing ReplaceWith on deprecations

Pull Request resolved: https://github.com/facebook/react-native/pull/51144

Test Plan:
```sh
yarn android
yarn test-android
```

Reviewed By: fabriziocucci

Differential Revision: D74327121

Pulled By: javache

fbshipit-source-id: 5b338531210bef104208d14cbd0e3320dc566b8e
This commit is contained in:
Mateo Guzmán
2025-05-07 10:09:35 -07:00
committed by Facebook GitHub Bot
parent cf94070416
commit 84253c4e20
10 changed files with 28 additions and 13 deletions
@@ -43,7 +43,8 @@ public class MemoryPressureRouter(context: Context) : ComponentCallbacks2 {
override public fun onConfigurationChanged(newConfig: Configuration): Unit = Unit
@Deprecated("onLowMemory is deprecated in the underlying API")
@Deprecated(
"onLowMemory is deprecated, use onTrimMemory instead.", ReplaceWith("onTrimMemory(level)"))
override public fun onLowMemory(): Unit = Unit
private fun dispatchMemoryPressure(level: Int) {
@@ -23,7 +23,8 @@ internal class EventAnimationDriver(
private val eventPath: List<String>,
@JvmField internal var valueNode: ValueAnimatedNode
) : RCTModernEventEmitter {
@Deprecated("Deprecated in Java")
@Deprecated(
"Deprecated in Java", ReplaceWith("receiveEvent(surfaceId, targetTag, eventName, params)"))
override fun receiveEvent(targetTag: Int, eventName: String, params: WritableMap?) =
receiveEvent(-1, targetTag, eventName, params)
@@ -16,7 +16,9 @@ import com.facebook.react.uimanager.events.RCTModernEventEmitter
import com.facebook.systrace.Systrace
internal class FabricEventEmitter(private val uiManager: FabricUIManager) : RCTModernEventEmitter {
@Deprecated("Deprecated in Java")
@Deprecated(
"Use receiveEvent with surfaceId instead.",
ReplaceWith("receiveEvent(surfaceId, targetTag, eventName, params)"))
override fun receiveEvent(targetTag: Int, eventName: String, params: WritableMap?): Unit {
receiveEvent(ViewUtil.NO_SURFACE_ID, targetTag, eventName, params)
}
@@ -154,14 +154,14 @@ internal class BridgelessCatalystInstance(private val reactHost: ReactHostImpl)
@Deprecated(
message =
"This class is deprecated, please to migrate to new architecture using [com.facebook.react.defaults.DefaultReactHost] instead.")
"This class is deprecated, please migrate to new architecture using [com.facebook.react.defaults.DefaultReactHost] instead.")
override fun setTurboModuleRegistry(turboModuleRegistry: TurboModuleRegistry) {
throw UnsupportedOperationException("Unimplemented method 'setTurboModuleRegistry'")
}
@Deprecated(
message =
"This class is deprecated, please to migrate to new architecture using [com.facebook.react.defaults.DefaultReactHost] instead.")
"This class is deprecated, please migrate to new architecture using [com.facebook.react.defaults.DefaultReactHost] instead.")
override fun setFabricUIManager(fabricUIManager: UIManager) {
throw UnsupportedOperationException("Unimplemented method 'setFabricUIManager'")
}
@@ -35,7 +35,9 @@ public interface ViewManagerDelegate<T : View> {
public fun setProperty(view: T, propName: String, value: Any?)
@Suppress("INAPPLICABLE_JVM_NAME")
@Deprecated(message = "propName is not nullable, please update your method signature")
@Deprecated(
message = "propName is not nullable, please update your method signature",
replaceWith = ReplaceWith("setProperty(view, propName, value)"))
@JvmName("setProperty")
public fun javaCompat_setProperty(view: T, propName: String?, value: Any?): Unit =
setProperty(view, checkNotNull(propName), value)
@@ -56,7 +58,9 @@ public interface ViewManagerDelegate<T : View> {
public fun receiveCommand(view: T, commandName: String, args: ReadableArray?)
@Suppress("INAPPLICABLE_JVM_NAME")
@Deprecated(message = "commandName is not nullable, please update your method signature")
@Deprecated(
message = "commandName is not nullable, please update your method signature",
replaceWith = ReplaceWith("receiveCommand(view, commandName, args)"))
@JvmName("receiveCommand")
public fun javaCompat_receiveCommand(view: T, commandName: String?, args: ReadableArray?): Unit =
receiveCommand(view, checkNotNull(commandName), args)
@@ -52,7 +52,8 @@ public abstract class Event<T : Event<T>> {
protected constructor()
@Deprecated("Use constructor with explicit surfaceId instead")
@Deprecated(
"Use constructor with explicit surfaceId instead", ReplaceWith("Event(surfaceId, viewTag)"))
protected constructor(viewTag: Int) {
init(viewTag)
}
@@ -61,7 +62,8 @@ public abstract class Event<T : Event<T>> {
init(surfaceId, viewTag)
}
@Deprecated("Use version with explicit surfaceId instead")
@Deprecated(
"Use version with explicit surfaceId instead", ReplaceWith("init(surfaceId, viewTag)"))
protected fun init(viewTag: Int) {
init(-1, viewTag)
}
@@ -40,7 +40,9 @@ internal class EventEmitterImpl(
fabricEventEmitter = eventEmitter
}
@Deprecated("Please use RCTModernEventEmitter")
@Deprecated(
"Please use RCTModernEventEmitter instead",
ReplaceWith("RCTModernEventEmitter.receiveEvent(surfaceId, targetTag, eventName, params)"))
override fun receiveEvent(targetTag: Int, eventName: String, params: WritableMap?) {
receiveEvent(-1, targetTag, eventName, params)
}
@@ -44,7 +44,8 @@ internal open class ReactImageDownloadListener<INFO> :
override fun setColorFilter(colorFilter: ColorFilter?) = Unit
@Deprecated("Deprecated in Java") override fun getOpacity(): Int = PixelFormat.OPAQUE
@Deprecated("Deprecated in Java", ReplaceWith("PixelFormat.OPAQUE"))
override fun getOpacity(): Int = PixelFormat.OPAQUE
}
companion object {
@@ -178,7 +178,9 @@ constructor(private val fpsListener: FpsListener? = null) :
}
}
@Deprecated("Use different receiveCommand overloads")
@Deprecated(
"Use receiveCommand with String commandId instead",
ReplaceWith("receiveCommand(scrollView, commandId, args)"))
override fun receiveCommand(
scrollView: ReactHorizontalScrollView,
commandId: Int,
@@ -152,7 +152,7 @@ class ShareModuleTest {
errorMessage = message ?: throwable?.message ?: ERROR_DEFAULT_MESSAGE
}
@Deprecated("Method deprecated")
@Deprecated("Method deprecated", ReplaceWith("reject(code, message)"))
override fun reject(message: String) {
reject(null, message, null, null)
}