Skip to content

Commit 5a290c4

Browse files
javachefacebook-github-bot
authored andcommitted
Fix nullability of ViewManagerDelegate method args (#48602)
Summary: Pull Request resolved: #48602 See context in D64532446 / #47086 These argument types were already consumed as nullable in various OSS libraries, which prevents correct Kotlin migration of this code. Changelog: [Android][Changed] Deprecated ViewManagerDelegate#setProperty and ViewManagerDelegate#receiveCommand Reviewed By: mdvacca Differential Revision: D67277871 fbshipit-source-id: a0743584891c7b2b4b50fff11de15da0078d5a1a
1 parent 90d2f65 commit 5a290c4

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -4041,6 +4041,8 @@ public abstract class com/facebook/react/uimanager/BaseViewManager : com/faceboo
40414041
public abstract class com/facebook/react/uimanager/BaseViewManagerDelegate : com/facebook/react/uimanager/ViewManagerDelegate {
40424042
protected final field mViewManager Lcom/facebook/react/uimanager/BaseViewManager;
40434043
public fun <init> (Lcom/facebook/react/uimanager/BaseViewManager;)V
4044+
public synthetic fun kotlinCompat$receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
4045+
public synthetic fun kotlinCompat$setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
40444046
public fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
40454047
public fun setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
40464048
}
@@ -5231,8 +5233,10 @@ public abstract class com/facebook/react/uimanager/ViewManager : com/facebook/re
52315233
}
52325234

52335235
public abstract interface class com/facebook/react/uimanager/ViewManagerDelegate {
5234-
public abstract fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
5235-
public abstract fun setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
5236+
public abstract synthetic fun kotlinCompat$receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
5237+
public abstract synthetic fun kotlinCompat$setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
5238+
public fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
5239+
public fun setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
52365240
}
52375241

52385242
public class com/facebook/react/uimanager/ViewManagerPropertyUpdater {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public abstract class BaseViewManagerDelegate<
2323
T : View, U : BaseViewManager<T, out LayoutShadowNode>>(
2424
@Suppress("NoHungarianNotation") @JvmField protected val mViewManager: U
2525
) : ViewManagerDelegate<T> {
26-
@Suppress("DEPRECATION")
27-
override public fun setProperty(view: T, propName: String?, value: Any?) {
26+
@Suppress("ACCIDENTAL_OVERRIDE", "DEPRECATION")
27+
override public fun setProperty(view: T, propName: String, value: Any?) {
2828
when (propName) {
2929
ViewProps.ACCESSIBILITY_ACTIONS ->
3030
mViewManager.setAccessibilityActions(view, value as ReadableArray?)
@@ -146,6 +146,7 @@ public abstract class BaseViewManagerDelegate<
146146
}
147147
}
148148

149-
override public fun receiveCommand(view: T, commandName: String?, args: ReadableArray?): Unit =
149+
@Suppress("ACCIDENTAL_OVERRIDE")
150+
override public fun receiveCommand(view: T, commandName: String, args: ReadableArray?): Unit =
150151
Unit
151152
}

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

+28-6
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,42 @@ public interface ViewManagerDelegate<T : View> {
2222
/**
2323
* Sets a property on a view managed by this view manager.
2424
*
25+
* We mark this method as synthetic / hide it from JVM so Java callers will call the deprecated
26+
* version and overrides work correctly.
27+
*
2528
* @param view the view to set the property on
26-
* @param propName the name of the property to set (NOTE: should be `String` but is kept as
27-
* `String?` to avoid breaking changes)
29+
* @param propName the name of the property to set
2830
* @param value the value to set the property to
2931
*/
30-
public fun setProperty(view: T, propName: String?, value: Any?)
32+
@Suppress("INAPPLICABLE_JVM_NAME")
33+
@JvmName("kotlinCompat\$setProperty")
34+
@JvmSynthetic
35+
public fun setProperty(view: T, propName: String, value: Any?)
36+
37+
@Suppress("INAPPLICABLE_JVM_NAME")
38+
@Deprecated(message = "propName is not nullable, please update your method signature")
39+
@JvmName("setProperty")
40+
public fun javaCompat_setProperty(view: T, propName: String?, value: Any?): Unit =
41+
setProperty(view, checkNotNull(propName), value)
3142

3243
/**
3344
* Executes a command from JS to the view
3445
*
46+
* We mark this method as synthetic / hide it from JVM so Java callers will call the deprecated
47+
* version and overrides work correctly.
48+
*
3549
* @param view the view to execute the command on
36-
* @param commandName the name of the command to execute (NOTE: should be `String` but is kept as
37-
* `String?` to avoid breaking changes)
50+
* @param commandName the name of the command to execute
3851
* @param args the arguments to pass to the command
3952
*/
40-
public fun receiveCommand(view: T, commandName: String?, args: ReadableArray?)
53+
@Suppress("INAPPLICABLE_JVM_NAME")
54+
@JvmName("kotlinCompat\$receiveCommand")
55+
@JvmSynthetic
56+
public fun receiveCommand(view: T, commandName: String, args: ReadableArray?)
57+
58+
@Suppress("INAPPLICABLE_JVM_NAME")
59+
@Deprecated(message = "commandName is not nullable, please update your method signature")
60+
@JvmName("receiveCommand")
61+
public fun javaCompat_receiveCommand(view: T, commandName: String?, args: ReadableArray?): Unit =
62+
receiveCommand(view, checkNotNull(commandName), args)
4163
}

0 commit comments

Comments
 (0)