Undo breaking change on ViewManagerDelegate.kt String params (#47086)

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

When we migrated `ViewManagerDelegate` to Kotlin, we convered his string params to be `String` (rather than `String?`).

Existing implementation of this interface in OSS written in Kotlin were using `String?` due to this interface being in Java (and not being Nullsafe annotated).
Therefore now changing this interface from `String?` to `String` is a breaking change for them.

Affected libraries are:
https://github.com/search?q=%22fun+receiveCommand%28%22+%22commandId%3A+String%3F%22+%22args%3A+ReadableArray%22+language%3Akotlin+-org%3Afacebook+-is%3Afork&type=code&p=4

This prevents the breaking change and should be included in 0.76.

Changelog:
[Android] [Fixed] - Undo breaking change on ViewManagerDelegate.kt String params

Reviewed By: cipolleschi

Differential Revision: D64532446

fbshipit-source-id: aac286554ad0e35f557160f900bcbad1acc5930d
This commit is contained in:
Nicola Corti
2024-10-17 04:45:05 -07:00
committed by Riccardo Cipolleschi
parent ab0d812cc6
commit ce1620616c
2 changed files with 21 additions and 4 deletions
@@ -22,7 +22,7 @@ import com.facebook.yoga.YogaConstants
public abstract class BaseViewManagerDelegate<T : View, U : BaseViewManagerInterface<T>>(
@Suppress("NoHungarianNotation") @JvmField protected val mViewManager: U
) : ViewManagerDelegate<T> {
override public fun setProperty(view: T, propName: String, value: Any?) {
override public fun setProperty(view: T, propName: String?, value: Any?) {
when (propName) {
ViewProps.ACCESSIBILITY_ACTIONS ->
mViewManager.setAccessibilityActions(view, value as ReadableArray?)
@@ -104,6 +104,6 @@ public abstract class BaseViewManagerDelegate<T : View, U : BaseViewManagerInter
}
}
override public fun receiveCommand(view: T, commandName: String, args: ReadableArray?): Unit =
override public fun receiveCommand(view: T, commandName: String?, args: ReadableArray?): Unit =
Unit
}
@@ -18,7 +18,24 @@ import com.facebook.react.bridge.ReadableArray
* @param <T> the type of the view supported by this delegate </T>
*/
public interface ViewManagerDelegate<T : View?> {
public fun setProperty(view: T, propName: String, value: Any?)
public fun receiveCommand(view: T, commandName: String, args: ReadableArray?)
/**
* Sets a property on a view managed by this view manager.
*
* @param view the view to set the property on
* @param propName the name of the property to set (NOTE: should be `String` but is kept as
* `String?` to avoid breaking changes)
* @param value the value to set the property to
*/
public fun setProperty(view: T, propName: String?, value: Any?)
/**
* Executes a command from JS to the view
*
* @param view the view to execute the command on
* @param commandName the name of the command to execute (NOTE: should be `String` but is kept as
* `String?` to avoid breaking changes)
* @param args the arguments to pass to the command
*/
public fun receiveCommand(view: T, commandName: String?, args: ReadableArray?)
}